PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.2
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.2
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / classes / class-wpfnl-order-bump-actions.php

class-wpfnl-order-bump-actions.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.2, at classes/class-wpfnl-order-bump-actions.php

1,062 lines 33.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This class is responsible for accept / reject order bump in frontend
4 *
5 * @package
6 */
7 namespace WPFunnels\Classes\OrderBumpActions;
8
9 use Error;
10 use WPFunnels\Meta\Wpfnl_Default_Meta;
11 use WPFunnels\Traits\SingletonTrait;
12 use WPFunnels\Wpfnl_functions;
13 use WPFunnels\Modules\Frontend\Checkout\Wpfnl_Order_Bump_Rules;
14
15 class Wpfnl_Order_Bump_Action {
16
17 use SingletonTrait;
18
19 protected $ob_settings;
20 protected $current_ob_settings;
21 protected $selected_ob;
22 protected $checkout_id;
23
24 /**
25 * Counts how many times each (checkout_id, bump key) pair has been
26 * rendered on this request. Some checkout layouts (e.g. the express
27 * checkout's two-column form) call `woocommerce_order_review()` more than
28 * once, which fires the order bump position hooks more than once too, so
29 * the same bump's markup ends up on the page more than once. Every
30 * occurrence still needs to work (it may be the one the customer actually
31 * sees), so instead of suppressing the repeats we give each render its
32 * own instance number and use it to keep the checkbox's `id`/`for` pair
33 * unique per occurrence -- see $render_instance below.
34 *
35 * @var array
36 */
37 protected static $render_counts = array();
38
39 /**
40 * The 0-based occurrence number of the bump currently being rendered,
41 * for the (checkout_id, key) pair being processed. Templates use this to
42 * suffix the checkbox's id/for attributes so duplicate renders on the
43 * same page never collide -- `data-key` (still just $key) is what JS
44 * uses to keep every occurrence of the same bump in sync.
45 *
46 * @var int
47 */
48 public $render_instance = 0;
49
50 /**
51 * @param int|string $checkout_id
52 * @param int|string $key
53 *
54 * @return void
55 */
56 private function mark_bump_render_instance( $checkout_id, $key ) {
57 $cache_key = $checkout_id . ':' . $key;
58 $this->render_instance = isset( self::$render_counts[ $cache_key ] ) ? self::$render_counts[ $cache_key ] : 0;
59 self::$render_counts[ $cache_key ] = $this->render_instance + 1;
60 }
61
62 public function __construct() {
63
64 add_action( 'woocommerce_checkout_after_order_review', array( $this, 'add_order_bump_hidden_fields' ), 99 );
65 add_action( 'wpfunnels/elementor_render_order_bump', array( $this, 'load_elementor_actions' ), 9999, 2 );
66 add_action( 'wpfunnels/bricks_render_order_bump', array( $this, 'load_elementor_actions' ), 9999, 2 );
67 add_action( 'wpfunnels/gb_render_order_bump_ajax', array( $this, 'load_gb_actions' ), 10, 2 );
68 add_action( 'wpfunnels/before_checkout_form', array( $this, 'load_actions' ), 10, 2 );
69 add_action( 'woocommerce_checkout_update_order_review', array( $this, 'load_ajax_actions' ), 5 );
70
71 }
72
73
74
75 public function add_order_bump_hidden_fields() {
76 $checkout_meta = new Wpfnl_Default_Meta();
77
78 $is_order_bump_enabled = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump');
79
80 $this->ob_settings = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta());
81 foreach( $this->ob_settings as $key=>$settings ){
82 if ( $settings['isEnabled'] ) {
83 $in_cart = isset( $settings['product'] ) && $this->is_order_bump_in_cart( $settings['product'] );
84 echo '<input type="hidden" name="_wpfunnels_order_bump_product_'.$key.'" value="'.( $in_cart ? esc_attr( $settings['product'] ) : '' ).'">';
85 echo '<input type="hidden" name="_wpfunnels_order_bump_clicked" value="">';
86 }
87 }
88 }
89
90
91 /**
92 * Load action hooks during the update_order_review AJAX request.
93 *
94 * `wpfunnels/before_checkout_form` only fires while the full checkout form is
95 * rendered, so on an AJAX refresh nothing would be listening on
96 * `wpfunnels/after_order_total`. An `after-order` bump would then be dropped from
97 * the refreshed `.wpfnl-after-order-total` fragment and disappear from the page.
98 *
99 * @return void
100 */
101 public function load_ajax_actions() {
102 $checkout_id = Wpfnl_functions::get_checkout_id_from_post( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
103
104 if ( ! $checkout_id ) {
105 return;
106 }
107
108 // render_order_bump_after_order() falls back to this property when $post is
109 // unavailable, which is always the case during this AJAX request.
110 $this->checkout_id = (int) $checkout_id;
111
112 $this->load_actions( $checkout_id );
113 }
114
115
116 public function load_actions( $checkout_id, $settings = array() ) {
117 if( !function_exists( 'is_plugin_active' ) ) {
118 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
119 if( is_plugin_active( 'elementor/elementor.php' ) ) {
120 if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
121 return false;
122 }
123 }
124 }
125 else {
126 if( is_plugin_active( 'elementor/elementor.php' ) ) {
127 if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
128 return false;
129 }
130 }
131 }
132
133 $checkout_meta = new Wpfnl_Default_Meta();
134 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
135 $this->ob_settings = $checkout_meta->get_checkout_meta_value( $checkout_id, 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta() );
136 $this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id );
137
138 $this->trigger_ob_actions();
139 }
140
141
142
143 /**
144 * Load elementor action for order bump preview
145 *
146 * @param $checkout_id
147 * @param $settings
148 *
149 * @return void
150 * @since 2.0.4
151 */
152 public function load_elementor_actions( $checkout_id, $settings ) {
153 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
154 $this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $settings, $funnel_id, $checkout_id );
155 $this->checkout_id = $checkout_id;
156 $this->trigger_ob_actions();
157 }
158
159
160 /**
161 * Load action hooks for order bump render
162 *
163 * @param $checkout_id
164 * @param $ob_settings
165 *
166 * @return void
167 *
168 * @since 2.0.4
169 */
170 public function load_gb_actions( $checkout_id, $ob_settings ) {
171 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
172 $this->ob_settings = $ob_settings;
173 $this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id );
174 $this->trigger_ob_actions();
175 }
176
177
178
179 /**
180 * Trigger WC action for order bump
181 *
182 * @return void
183 *
184 * @since 2.0.4
185 */
186 private function trigger_ob_actions() {
187 if( is_array( $this->ob_settings ) ) {
188 foreach( $this->ob_settings as $key => $settings ) {
189 $this->current_ob_settings = $settings;
190 $position = $this->get_order_bump_attribute( $settings, 'position' );
191 $is_enabled = $this->get_order_bump_attribute( $settings, 'isEnabled' );
192
193 if( 'yes' === $is_enabled || 1 === (int)$is_enabled || 'true' == $is_enabled ) {
194 $is_enabled = true;
195 }
196 elseif( 'no' === $is_enabled || 0 === (int)$is_enabled || '' === $is_enabled ) {
197 $is_enabled = false;
198 }
199
200 if( !$position ) {
201 return;
202 }
203 if( !$is_enabled ) {
204 continue;
205 }
206
207 if( $position === 'before-checkout' ) {
208 add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump_before_checkout_form' ], 10 );
209 }
210 elseif( $position === 'after-order' ) {
211 add_action( 'wpfunnels/after_order_total', [ $this, 'render_order_bump_after_order' ], 10 );
212 }
213 elseif( $position === 'before-order' ) {
214 add_action( 'woocommerce_review_order_before_cart_contents', [ $this, 'render_order_bump_before_order' ], 10 );
215 }
216 elseif( $position === 'after-customer-details' ) {
217 add_action( 'woocommerce_after_order_notes', [ $this, 'render_order_bump_after_customer_details' ], 10 );
218 }
219 elseif( $position === 'before-payment' ) {
220 add_action( 'woocommerce_review_order_before_payment', [ $this, 'render_order_bump_before_payment' ], 10 );
221 }
222 elseif( $position === 'after-payment' ) {
223 add_action( 'woocommerce_review_order_after_payment', [ $this, 'render_order_bump_after_payment' ], 10 );
224 }
225 elseif( $position === 'after-lms-order' ) {
226 add_action( 'wpfunnels/after_lms_order_deatils', [ $this, 'render_order_bump_after_lms_order_deatils' ], 10 );
227 }
228 elseif( $position === 'before-lms-order' ) {
229 add_action( 'wpfunnels/before_lms_order_deatils', [ $this, 'render_order_bump_before_lms_order_deatils' ], 10 );
230 }
231 elseif( $position === 'popup' ) {
232 $this->ob_settings[ $key ][ 'selectedStyle' ] = 'popup';
233 $this->render_popup_in_elementor_editor();
234 }
235 }
236 }
237
238
239 }
240
241
242 /**
243 * Add order bump extra meta data
244 * to main settings data
245 *
246 * @param $ob_settings
247 * @param $funnel_id
248 * @param $checkout_id
249 *
250 * @return array
251 */
252 public function add_extra_ob_data( $ob_settings, $funnel_id, $checkout_id ) {
253 $ob_settings['step_id'] = $checkout_id;
254 $checkout_meta = new Wpfnl_Default_Meta();
255 $main_product_ids = $checkout_meta->get_main_product_ids( $funnel_id, $checkout_id );
256 $ob_settings['main_products'] = $main_product_ids;
257 return $ob_settings;
258 }
259
260
261 /**
262 * Get order bump attribute from order bump settings data
263 *
264 * @param $order_bump_data
265 * @param $key
266 *
267 * @return bool|mixed
268 */
269 private function get_order_bump_attribute( $order_bump_data, $key ) {
270 if( !isset($order_bump_data[$key]) ) {
271 return false;
272 }
273 return $order_bump_data[$key];
274 }
275
276
277 /**
278 * Check if an order bump product is already present in the cart so the
279 * checkbox can be rendered as checked after a page reload.
280 *
281 * @param int|string $product_id product/variation id stored in the order bump settings
282 *
283 * @return bool
284 */
285 public function is_order_bump_in_cart( $product_id ) {
286 if ( ! Wpfnl_functions::is_wc_active() || ! WC()->cart ) {
287 return false;
288 }
289
290 foreach ( WC()->cart->get_cart() as $cart_item ) {
291 if ( empty( $cart_item['wpfnl_order_bump'] ) ) {
292 continue;
293 }
294
295 if ( $cart_item['product_id'] == $product_id || ( ! empty( $cart_item['variation_id'] ) && $cart_item['variation_id'] == $product_id ) ) {
296 return true;
297 }
298 }
299
300 return false;
301 }
302
303
304 /**
305 * Render popup style for order bump in elementor
306 * builder preview
307 *
308 * @since 2.0.3
309 */
310 public function render_popup_in_elementor_editor() {
311 if( Wpfnl_functions::is_elementor_active() ) {
312 if( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
313 add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 );
314 }
315 else {
316 add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 );
317 }
318 }
319 else {
320 add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 );
321 }
322 }
323
324
325 /**
326 * Render order bump markup
327 *
328 * @since 2.0.3
329 */
330 public function render_order_bump() {
331
332 global $post;
333 $checkout_id = 0;
334 $output = '';
335 if ( $post ) {
336 $checkout_id = $post->ID;
337 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
338 $checkout_id = intval( $_POST['post_id'] );
339 }
340
341
342 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
343 if ( ! empty( $_POST['order_bump_data'] ) ) {
344 $settings = $_POST['order_bump_data'];
345 } else {
346 $settings = $this->ob_settings;
347 }
348
349 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
350 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
351
352 foreach( $this->ob_settings as $key=> $settings ){
353
354 if( $settings['isEnabled'] && $settings['position'] == 'popup'){
355
356 $this->mark_bump_render_instance( $checkout_id, $key );
357
358 if( $settings['isEnabled'] === 'no' ){
359 continue;
360 }
361
362 // Check conditional rules before displaying
363 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
364 continue;
365 }
366
367 if (isset($settings['product']) && $settings['product'] != '') {
368 if ( !empty($settings['selectedStyle']) ) {
369
370 ob_start();
371 if ( $settings['position'] == 'popup' ) {
372 $is_editor = false;
373
374 if ( Wpfnl_functions::is_elementor_active() ) {
375 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
376 $is_editor = true;
377 }
378 } elseif ( is_admin() && ! wp_doing_ajax() ) {
379 $is_editor = true;
380 }
381
382 if ( $is_editor ) {
383 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
384 } else {
385 $order_bump_settings = $settings;
386 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
387 }
388 } else {
389 $order_bump_settings = $settings;
390 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
391 }
392 $output .= ob_get_clean();
393 }
394 }
395 else {
396 wc_clear_notices();
397 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
398 }
399 }
400 }
401 }
402
403 echo $output;
404 }
405
406 /**
407 * Render order bump markup
408 *
409 * @since 2.0.3
410 */
411 public function render_order_bump_before_checkout_form() {
412
413 global $post;
414 $checkout_id = 0;
415 $output = '';
416 if ( $post ) {
417 $checkout_id = $post->ID;
418 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
419 $checkout_id = intval( $_POST['post_id'] );
420 }
421
422 if( !$checkout_id ){
423 $checkout_id = $this->checkout_id;
424 }
425
426 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
427 if ( ! empty( $_POST['order_bump_data'] ) ) {
428 $settings = $_POST['order_bump_data'];
429 } else {
430 $settings = $this->ob_settings;
431 }
432
433 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
434 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
435
436 foreach( $this->ob_settings as $key=> $settings ){
437
438 if( $settings['isEnabled'] && $settings['position'] == 'before-checkout'){
439 $this->mark_bump_render_instance( $checkout_id, $key );
440 if( $settings['isEnabled'] === 'no' ){
441 continue;
442 }
443
444 // Check conditional rules before displaying
445 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
446 continue;
447 }
448
449 if (isset($settings['product']) && $settings['product'] != '') {
450 if ( !empty($settings['selectedStyle']) ) {
451 ob_start();
452 if ( $settings['position'] == 'popup' ) {
453 $is_editor = false;
454
455 if ( Wpfnl_functions::is_elementor_active() ) {
456 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
457 $is_editor = true;
458 }
459 } elseif ( is_admin() && ! wp_doing_ajax() ) {
460 $is_editor = true;
461 }
462
463 if ( $is_editor ) {
464 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
465 } else {
466 $order_bump_settings = $settings;
467 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
468 }
469 } else {
470 $order_bump_settings = $settings;
471 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
472 }
473 $output .= ob_get_clean();
474 }
475 }
476 else {
477 wc_clear_notices();
478 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
479 }
480 }
481 }
482
483 }
484
485 echo $output;
486 }
487
488
489 /**
490 * Render order bump markup
491 *
492 * @since 2.0.3
493 */
494 public function render_order_bump_before_lms_order_deatils() {
495
496 global $post;
497 $checkout_id = 0;
498 $output = '';
499 if ( $post ) {
500 $checkout_id = $post->ID;
501 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
502 $checkout_id = intval( $_POST['post_id'] );
503 }
504
505 if( !$checkout_id ){
506 $checkout_id = $this->checkout_id;
507 }
508
509 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
510 if ( ! empty( $_POST['order_bump_data'] ) ) {
511 $settings = $_POST['order_bump_data'];
512 } else {
513 $settings = $this->ob_settings;
514 }
515 $funnel_id = get_post_meta($checkout_id,'_funnel_id',true);
516 $type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true);
517 foreach( $this->ob_settings as $key=> $settings ){
518
519 if( $settings['isEnabled'] && $settings['position'] == 'before-lms-order'){
520 $this->mark_bump_render_instance( $checkout_id, $key );
521 if( $settings['isEnabled'] === 'no' ){
522 continue;
523 }
524
525 // Check conditional rules before displaying
526 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
527 continue;
528 }
529
530 if (isset($settings['product']) && $settings['product'] != '') {
531 if ( !empty($settings['selectedStyle']) ) {
532 ob_start();
533 if ( $settings['position'] == 'popup' ) {
534 $is_editor = false;
535
536 if ( Wpfnl_functions::is_elementor_active() ) {
537 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
538 $is_editor = true;
539 }
540 } elseif ( is_admin() && ! wp_doing_ajax() ) {
541 $is_editor = true;
542 }
543
544 if ( $is_editor ) {
545 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
546 } else {
547 $order_bump_settings = $settings;
548 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
549 }
550 } else {
551 $order_bump_settings = $settings;
552 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
553 }
554 $output .= ob_get_clean();
555 }
556 }
557 else {
558 wc_clear_notices();
559 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
560 }
561 }
562 }
563
564 }
565
566 echo $output;
567 }
568
569
570 /**
571 * Render order bump markup
572 *
573 * @since 2.0.3
574 */
575 public function render_order_bump_after_lms_order_deatils() {
576
577 global $post;
578 $checkout_id = 0;
579 $output = '';
580 if ( $post ) {
581 $checkout_id = $post->ID;
582 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
583 $checkout_id = intval( $_POST['post_id'] );
584 }
585
586 if( !$checkout_id ){
587 $checkout_id = $this->checkout_id;
588 }
589 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
590 if ( ! empty( $_POST['order_bump_data'] ) ) {
591 $settings = $_POST['order_bump_data'];
592 } else {
593 $settings = $this->ob_settings;
594 }
595
596 $funnel_id = get_post_meta($checkout_id,'_funnel_id',true);
597 $type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true);
598 foreach( $this->ob_settings as $key=> $settings ){
599
600 if( $settings['isEnabled'] && $settings['position'] == 'after-lms-order'){
601 $this->mark_bump_render_instance( $checkout_id, $key );
602 if( $settings['isEnabled'] === 'no' ){
603 continue;
604 }
605
606 // Check conditional rules before displaying
607 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
608 continue;
609 }
610
611 if (isset($settings['product']) && $settings['product'] != '') {
612 if ( !empty($settings['selectedStyle']) ) {
613 ob_start();
614 if ( $settings['position'] == 'popup' ) {
615 $is_editor = false;
616
617 if ( Wpfnl_functions::is_elementor_active() ) {
618 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
619 $is_editor = true;
620 }
621 } elseif ( is_admin() && ! wp_doing_ajax() ) {
622 $is_editor = true;
623 }
624
625 if ( $is_editor ) {
626 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
627 } else {
628 $order_bump_settings = $settings;
629 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
630 }
631 } else {
632 $order_bump_settings = $settings;
633 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
634 }
635 $output .= ob_get_clean();
636 }
637 }
638 else {
639 wc_clear_notices();
640 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
641 }
642 }
643 }
644
645 }
646
647 echo $output;
648 }
649
650 /**
651 * Render order bump markup
652 *
653 * @since 2.0.3
654 */
655 public function render_order_bump_before_payment() {
656
657
658 global $post;
659 $checkout_id = 0;
660 $output = '';
661 if ( $post ) {
662 $checkout_id = $post->ID;
663 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
664 $checkout_id = intval( $_POST['post_id'] );
665 }
666
667 if( !$checkout_id ){
668 $checkout_id = $this->checkout_id;
669 }
670 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
671 if ( ! empty( $_POST['order_bump_data'] ) ) {
672 $settings = $_POST['order_bump_data'];
673 } else {
674 $settings = $this->ob_settings;
675 }
676 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
677 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
678
679 foreach( $this->ob_settings as $key=> $settings ){
680
681 if( $settings['isEnabled'] && $settings['position'] == 'before-payment'){
682 $this->mark_bump_render_instance( $checkout_id, $key );
683 if( $settings['isEnabled'] === 'no' ){
684 continue;
685 }
686
687 // Check conditional rules before displaying
688 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
689 continue;
690 }
691
692 if (isset($settings['product']) && $settings['product'] != '') {
693 if ( !empty($settings['selectedStyle']) ) {
694 ob_start();
695 if ( $settings['position'] == 'popup' ) {
696 $is_editor = false;
697
698 if ( Wpfnl_functions::is_elementor_active() ) {
699 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
700 $is_editor = true;
701 }
702 } elseif ( is_admin() && ! wp_doing_ajax() ) {
703 $is_editor = true;
704 }
705
706 if ( $is_editor ) {
707 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
708 } else {
709 $order_bump_settings = $settings;
710 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
711 }
712 } else {
713 $order_bump_settings = $settings;
714 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
715 }
716 $output .= ob_get_clean();
717 }
718 }
719 else {
720 wc_clear_notices();
721 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
722 }
723 }
724 }
725
726 }
727
728 echo $output;
729 }
730
731
732 /**
733 * Render order bump markup
734 *
735 * @since 2.0.3
736 */
737 public function render_order_bump_after_payment() {
738
739 global $post;
740 $checkout_id = 0;
741 $output = '';
742
743 if ( $post ) {
744 $checkout_id = $post->ID;
745 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
746 $checkout_id = intval( $_POST['post_id'] );
747 }
748 if( !$checkout_id ){
749 $checkout_id = $this->checkout_id;
750 }
751 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
752 if ( ! empty( $_POST['order_bump_data'] ) ) {
753 $settings = $_POST['order_bump_data'];
754 } else {
755 $settings = $this->ob_settings;
756 }
757
758 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
759 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
760
761 foreach( $this->ob_settings as $key=> $settings ){
762
763 if( $settings['isEnabled'] && $settings['position'] == 'after-payment'){
764 $this->mark_bump_render_instance( $checkout_id, $key );
765 if( $settings['isEnabled'] === 'no' ){
766 continue;
767 }
768
769 // Check conditional rules before displaying
770 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
771 continue;
772 }
773
774 if (isset($settings['product']) && $settings['product'] != '') {
775 if ( !empty($settings['selectedStyle']) ) {
776 ob_start();
777 if ( $settings['position'] == 'popup' ) {
778 $is_editor = false;
779
780 if ( Wpfnl_functions::is_elementor_active() ) {
781 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
782 $is_editor = true;
783 }
784 } elseif ( is_admin() && ! wp_doing_ajax() ) {
785 $is_editor = true;
786 }
787
788 if ( $is_editor ) {
789 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
790 } else {
791 $order_bump_settings = $settings;
792 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
793 }
794 } else {
795 $order_bump_settings = $settings;
796 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
797 }
798 $output .= ob_get_clean();
799 }
800 }
801 else {
802 wc_clear_notices();
803 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
804 }
805 }
806 }
807
808 }
809
810 echo $output;
811 }
812
813
814 /**
815 * Render order bump markup
816 *
817 * @since 2.0.3
818 */
819 public function render_order_bump_after_customer_details() {
820
821 global $post;
822 $checkout_id = 0;
823 $output = '';
824 if ( $post ) {
825 $checkout_id = $post->ID;
826 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
827 $checkout_id = intval( $_POST['post_id'] );
828 }
829
830 if( !$checkout_id ){
831 $checkout_id = $this->checkout_id;
832 }
833
834 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
835 if ( ! empty( $_POST['order_bump_data'] ) ) {
836 $settings = $_POST['order_bump_data'];
837 } else {
838 $settings = $this->ob_settings;
839 }
840
841 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
842 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
843
844 foreach( $this->ob_settings as $key=> $settings ){
845 if( $settings['isEnabled'] && $settings['position'] == 'after-customer-details'){
846 $this->mark_bump_render_instance( $checkout_id, $key );
847 if( $settings['isEnabled'] === 'no' ){
848 continue;
849 }
850 // Check conditional rules before displaying
851 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
852 continue;
853 }
854 if (isset($settings['product']) && $settings['product'] != '') {
855 if ( !empty($settings['selectedStyle']) ) {
856 ob_start();
857 if ( $settings['position'] == 'popup' ) {
858 $is_editor = false;
859
860 if ( Wpfnl_functions::is_elementor_active() ) {
861 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
862 $is_editor = true;
863 }
864 } elseif ( is_admin() && ! wp_doing_ajax() ) {
865 $is_editor = true;
866 }
867
868 if ( $is_editor ) {
869 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
870 } else {
871 $order_bump_settings = $settings;
872 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
873 }
874 } else {
875 $order_bump_settings = $settings;
876 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
877 }
878 $output .= ob_get_clean();
879 }
880 }
881 else {
882 wc_clear_notices();
883 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
884 }
885 }
886 }
887
888 }
889
890 echo $output;
891 }
892
893
894 /**
895 * Render order bump markup
896 *
897 * @since 2.0.3
898 */
899 public function render_order_bump_after_order() {
900
901 global $post;
902 $checkout_id = 0;
903 $output = '';
904
905 if ( $post ) {
906 $checkout_id = $post->ID;
907 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
908 $checkout_id = intval( $_POST['post_id'] );
909 }
910
911 if( !$checkout_id ){
912 $checkout_id = $this->checkout_id;
913 }
914
915 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
916 if ( ! empty( $_POST['order_bump_data'] ) ) {
917 $settings = $_POST['order_bump_data'];
918 } else {
919 $settings = $this->ob_settings;
920 }
921
922 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
923 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
924 foreach( $this->ob_settings as $key=> $settings ){
925
926 if( $settings['isEnabled'] && $settings['position'] == 'after-order'){
927
928 $this->mark_bump_render_instance( $checkout_id, $key );
929
930 if( $settings['isEnabled'] === 'no' ){
931 continue;
932 }
933
934 // Check conditional rules before displaying
935 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
936 continue;
937 }
938
939 if (isset($settings['product']) && $settings['product'] != '') {
940 if ( !empty($settings['selectedStyle']) ) {
941 ob_start();
942 if ( $settings['position'] == 'popup' ) {
943 $is_editor = false;
944
945 if ( Wpfnl_functions::is_elementor_active() ) {
946 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
947 $is_editor = true;
948 }
949 } elseif ( is_admin() && ! wp_doing_ajax() ) {
950 $is_editor = true;
951 }
952
953 if ( $is_editor ) {
954 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
955 } else {
956 $order_bump_settings = $settings;
957 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
958 }
959 } else {
960 $order_bump_settings = $settings;
961 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
962 }
963 $output .= ob_get_clean();
964 }
965 }
966 else {
967 wc_clear_notices();
968 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
969 }
970 }
971 }
972
973 }
974
975 echo $output;
976 }
977
978
979 /**
980 * Render order bump markup
981 *
982 * @since 2.0.3
983 */
984 public function render_order_bump_before_order() {
985
986 global $post;
987 $checkout_id = 0;
988 $output = '';
989
990
991 if ( $post ) {
992 $checkout_id = $post->ID;
993 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
994 $checkout_id = intval( $_POST['post_id'] );
995 }
996
997 if( !$checkout_id ){
998 $checkout_id = $this->checkout_id;
999 }
1000
1001 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
1002 if ( ! empty( $_POST['order_bump_data'] ) ) {
1003 $settings = $_POST['order_bump_data'];
1004 } else {
1005 $settings = $this->ob_settings;
1006 }
1007
1008 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
1009 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
1010
1011 foreach( $this->ob_settings as $key=> $settings ){
1012
1013 if( $settings['isEnabled'] && $settings['position'] == 'before-order'){
1014 $this->mark_bump_render_instance( $checkout_id, $key );
1015 if( $settings['isEnabled'] === 'no' ){
1016 continue;
1017 }
1018
1019 // Check conditional rules before displaying
1020 if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
1021 continue;
1022 }
1023
1024 if (isset($settings['product']) && $settings['product'] != '') {
1025 if ( !empty($settings['selectedStyle']) ) {
1026 ob_start();
1027 if ( $settings['position'] == 'popup' ) {
1028 $is_editor = false;
1029
1030 if ( Wpfnl_functions::is_elementor_active() ) {
1031 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
1032 $is_editor = true;
1033 }
1034 } elseif ( is_admin() && ! wp_doing_ajax() ) {
1035 $is_editor = true;
1036 }
1037
1038 if ( $is_editor ) {
1039 echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
1040 } else {
1041 $order_bump_settings = $settings;
1042 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
1043 }
1044 } else {
1045 $order_bump_settings = $settings;
1046 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
1047 }
1048 $output .= ob_get_clean();
1049 }
1050 }
1051 else {
1052 wc_clear_notices();
1053 wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error');
1054 }
1055 }
1056 }
1057
1058 }
1059
1060 echo $output;
1061 }
1062 }