PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / classes / class-cartflows-frontend.php

class-cartflows-frontend.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.1.0, at classes/class-cartflows-frontend.php

326 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Frontend.
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Class Cartflows_Frontend.
10 */
11 class Cartflows_Frontend {
12
13 /**
14 * Member Variable
15 *
16 * @var instance
17 */
18 private static $instance;
19
20 /**
21 * Initiator
22 */
23 public static function get_instance() {
24 if ( ! isset( self::$instance ) ) {
25 self::$instance = new self;
26 }
27 return self::$instance;
28 }
29
30 /**
31 * Constructor
32 */
33 public function __construct() {
34
35 /* Set / Destroy Flow Sessions. Set data */
36 add_action( 'wp', array( $this, 'init_actions' ), 1 );
37
38 /* Enqueue global required scripts */
39 add_action( 'wp', array( $this, 'wp_actions' ), 55 );
40
41 /* Modify the checkout order received url to go thank you page in our flow */
42 add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'redirect_to_thankyou_page' ), 10, 2 );
43
44 add_filter( 'woocommerce_get_cancel_order_url_raw', array( $this, 'redirect_to_checkout_on_cancel' ), 10 );
45
46 }
47
48 /**
49 * Redirect to thank page if upsell not exists
50 *
51 * @param string $order_recieve_url url.
52 * @param object $order order object.
53 * @since 1.0.0
54 */
55 function redirect_to_thankyou_page( $order_recieve_url, $order ) {
56
57 /* Only for thank you page */
58 wcf()->logger->log( 'Start-' . __CLASS__ . '::' . __FUNCTION__ );
59 wcf()->logger->log( 'Only for thank you page' );
60
61 if ( wcf()->flow->is_thankyou_page_exists( $order ) ) {
62
63 if ( _is_wcf_doing_checkout_ajax() ) {
64
65 $checkout_id = wcf()->utils->get_checkout_id_from_post_data();
66
67 if ( ! $checkout_id ) {
68 $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
69 }
70 } else {
71 $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
72 }
73
74 wcf()->logger->log( 'Checkout ID : ' . $checkout_id );
75
76 if ( $checkout_id ) {
77
78 $thankyou_step_id = wcf()->flow->get_thankyou_page_id( $order );
79
80 if ( $thankyou_step_id ) {
81
82 $order_recieve_url = get_permalink( $thankyou_step_id );
83
84 $order_recieve_url = add_query_arg(
85 array(
86 'wcf-order' => $order->get_id(),
87 'wcf-key' => $order->get_order_key(),
88 ),
89 $order_recieve_url
90 );
91 }
92 }
93 }
94
95 wcf()->logger->log( 'End-' . __CLASS__ . '::' . __FUNCTION__ );
96
97 return $order_recieve_url;
98 }
99
100 /**
101 * Cancel and redirect to checkout
102 *
103 * @param string $return_url url.
104 * @since 1.0.0
105 */
106 function redirect_to_checkout_on_cancel( $return_url ) {
107
108 if ( _is_wcf_doing_checkout_ajax() ) {
109
110 $checkout_id = wcf()->utils->get_checkout_id_from_post_data();
111
112 if ( ! $checkout_id ) {
113 $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
114 }
115 } else {
116 $checkout_id = wcf()->utils->get_checkout_id_from_order( $order->get_id() );
117 }
118
119 if ( $checkout_id ) {
120
121 $return_url = add_query_arg(
122 array(
123 'cancel_order' => 'true',
124 '_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ),
125 ),
126 get_permalink( $checkout_id )
127 );
128 }
129
130 return $return_url;
131 }
132
133
134 /**
135 * Remove theme styles.
136 *
137 * @since 1.0.0
138 */
139 function remove_theme_styles() {
140
141 // get all styles data.
142 global $wp_styles;
143 global $wp_scripts;
144
145 $get_stylesheet = get_stylesheet();
146 $get_template = get_template();
147
148 if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
149 return;
150 }
151
152 $get_stylesheet = 'themes/' . get_stylesheet();
153 $get_template = 'themes/' . get_template();
154
155 // loop over all of the registered scripts..
156 foreach ( $wp_styles->registered as $handle => $data ) {
157
158 if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
159
160 // remove it.
161 wp_deregister_style( $handle );
162 wp_dequeue_style( $handle );
163 }
164 }
165
166 // loop over all of the registered scripts.
167 foreach ( $wp_scripts->registered as $handle => $data ) {
168
169 if ( strpos( $data->src, $get_template ) !== false || strpos( $data->src, $get_stylesheet ) !== false ) {
170
171 // remove it.
172 wp_deregister_script( $handle );
173 wp_dequeue_script( $handle );
174 }
175 }
176 }
177
178 /**
179 * Update main order data in transient.
180 *
181 * @param array $woo_styles new styles array.
182 * @since 1.0.0
183 * @return array.
184 */
185 function woo_default_css( $woo_styles ) {
186
187 $woo_styles = array(
188 'woocommerce-layout' => array(
189 'src' => plugins_url( 'assets/css/woocommerce-layout.css', WC_PLUGIN_FILE ),
190 'deps' => '',
191 'version' => WC_VERSION,
192 'media' => 'all',
193 'has_rtl' => true,
194 ),
195 'woocommerce-smallscreen' => array(
196 'src' => plugins_url( 'assets/css/woocommerce-smallscreen.css', WC_PLUGIN_FILE ),
197 'deps' => 'woocommerce-layout',
198 'version' => WC_VERSION,
199 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
200 'has_rtl' => true,
201 ),
202 'woocommerce-general' => array(
203 'src' => plugins_url( 'assets/css/woocommerce.css', WC_PLUGIN_FILE ),
204 'deps' => '',
205 'version' => WC_VERSION,
206 'media' => 'all',
207 'has_rtl' => true,
208 ),
209 );
210
211 return $woo_styles;
212 }
213
214 /**
215 * Init Actions.
216 *
217 * @since 1.0.0
218 */
219 function init_actions() {
220
221 $this->set_flow_session();
222 }
223
224 /**
225 * Set flow session.
226 *
227 * @since 1.0.0
228 */
229 function set_flow_session() {
230
231 if ( wcf()->utils->is_step_post_type() ) {
232
233 add_action( 'wp_head', array( $this, 'noindex_flow' ) );
234
235 wcf()->utils->do_not_cache();
236
237 /* Set key to support pixel */
238 if ( isset( $_GET['wcf-key'] ) ) {
239 $_GET['key'] = $_GET['wcf-key'];
240 $_REQUEST['key'] = $_GET['wcf-key'];
241 }
242 }
243 }
244
245 /**
246 * Add noindex, nofollow.
247 *
248 * @since 1.0.0
249 */
250 function noindex_flow() {
251
252 $common = Cartflows_Helper::get_common_settings();
253
254 if ( 'enable' === $common['disallow_indexing'] ) {
255 echo '<meta name="robots" content="noindex,nofollow">';
256 }
257 }
258
259 /**
260 * WP Actions.
261 *
262 * @since 1.0.0
263 */
264 function wp_actions() {
265
266 if ( wcf()->utils->is_step_post_type() ) {
267
268 /* CSS Compatibility for All theme */
269 add_filter( 'woocommerce_enqueue_styles', array( $this, 'woo_default_css' ), 9999 );
270
271 add_action( 'wp_enqueue_scripts', array( $this, 'remove_theme_styles' ), 9999 );
272
273 add_action( 'wp_enqueue_scripts', array( $this, 'global_flow_scripts' ), 20 );
274 }
275
276 }
277
278 /**
279 * Global flow scripts.
280 *
281 * @since 1.0.0
282 */
283 function global_flow_scripts() {
284
285 global $post;
286
287 $flow = get_post_meta( $post->ID, 'wcf-flow-id', true );
288 $current_step = $post->ID;
289 $next_step_link = '';
290 $compatibility = Cartflows_Compatibility::get_instance();
291
292 if ( _is_wcf_landing_type() ) {
293
294 $next_step_id = wcf()->utils->get_next_step_id( $flow, $current_step );
295 $next_step_link = get_permalink( $next_step_id );
296 }
297
298 $localize = array(
299 'ajax_url' => admin_url( 'admin-ajax.php' ),
300 'is_pb_preview' => $compatibility->is_page_builder_preview(),
301 'current_flow' => $flow,
302 'current_step' => $current_step,
303 'next_step' => $next_step_link,
304 );
305
306 wp_localize_script( 'jquery', 'cartflows', apply_filters( 'global_cartflows_js_localize', $localize ) );
307
308 wp_enqueue_style( 'wcf-frontend-global', CARTFLOWS_URL . 'assets/css/frontend.css', array(), CARTFLOWS_VER );
309 wp_style_add_data( 'wcf-frontend-global', 'rtl', 'replace' );
310
311 wp_enqueue_script(
312 'wcf-frontend-global',
313 CARTFLOWS_URL . 'assets/js/frontend.js',
314 array( 'jquery' ),
315 CARTFLOWS_VER,
316 true
317 );
318 }
319 }
320
321 /**
322 * Prepare if class 'Cartflows_Frontend' exist.
323 * Kicking this off by calling 'get_instance()' method
324 */
325 Cartflows_Frontend::get_instance();
326