PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.2
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.2
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.2, at classes/class-cartflows-frontend.php

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