PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
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
← All changes | classes/class-wpfnl-order-bump-actions.php +304 -74 2.8.16 → 3.13.3 View file →
@@ -5,11 +5,13 @@
5 5 * @package
6 6 */
7 7 namespace WPFunnels\Classes\OrderBumpActions;
8 8
9 +use Error;
9 10 use WPFunnels\Meta\Wpfnl_Default_Meta;
10 11 use WPFunnels\Traits\SingletonTrait;
11 12 use WPFunnels\Wpfnl_functions;
13 +use WPFunnels\Modules\Frontend\Checkout\Wpfnl_Order_Bump_Rules;
12 14
13 15 class Wpfnl_Order_Bump_Action {
14 16
15 17 use SingletonTrait;
@@ -16,15 +18,56 @@
16 18
17 19 protected $ob_settings;
18 20 protected $current_ob_settings;
19 21 protected $selected_ob;
22 + protected $checkout_id;
20 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 +
21 62 public function __construct() {
22 63
23 64 add_action( 'woocommerce_checkout_after_order_review', array( $this, 'add_order_bump_hidden_fields' ), 99 );
24 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 );
25 67 add_action( 'wpfunnels/gb_render_order_bump_ajax', array( $this, 'load_gb_actions' ), 10, 2 );
26 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 );
27 70
28 71 }
29 72
30 73
@@ -36,15 +79,38 @@
36 79
37 80 $this->ob_settings = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta());
38 81 foreach( $this->ob_settings as $key=>$settings ){
39 82 if ( $settings['isEnabled'] ) {
40 - echo '<input type="hidden" name="_wpfunnels_order_bump_product_'.$key.'" value="">';
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'] ) : '' ).'">';
41 85 echo '<input type="hidden" name="_wpfunnels_order_bump_clicked" value="">';
86 + }
87 + }
88 + }
42 89
43 - }
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;
44 106 }
45 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;
46 111
112 + $this->load_actions( $checkout_id );
47 113 }
48 114
49 115
50 116 public function load_actions( $checkout_id, $settings = array() ) {
@@ -85,8 +151,9 @@
85 151 */
86 152 public function load_elementor_actions( $checkout_id, $settings ) {
87 153 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
88 154 $this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $settings, $funnel_id, $checkout_id );
155 + $this->checkout_id = $checkout_id;
89 156 $this->trigger_ob_actions();
90 157 }
91 158
92 159
@@ -121,9 +188,9 @@
121 188 foreach( $this->ob_settings as $key => $settings ) {
122 189 $this->current_ob_settings = $settings;
123 190 $position = $this->get_order_bump_attribute( $settings, 'position' );
124 191 $is_enabled = $this->get_order_bump_attribute( $settings, 'isEnabled' );
125 -
192 +
126 193 if( 'yes' === $is_enabled || 1 === (int)$is_enabled || 'true' == $is_enabled ) {
127 194 $is_enabled = true;
128 195 }
129 196 elseif( 'no' === $is_enabled || 0 === (int)$is_enabled || '' === $is_enabled ) {
@@ -140,9 +207,9 @@
140 207 if( $position === 'before-checkout' ) {
141 208 add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump_before_checkout_form' ], 10 );
142 209 }
143 210 elseif( $position === 'after-order' ) {
144 - add_action( 'woocommerce_review_order_after_cart_contents', [ $this, 'render_order_bump_after_order' ], 10 );
211 + add_action( 'wpfunnels/after_order_total', [ $this, 'render_order_bump_after_order' ], 10 );
145 212 }
146 213 elseif( $position === 'before-order' ) {
147 214 add_action( 'woocommerce_review_order_before_cart_contents', [ $this, 'render_order_bump_before_order' ], 10 );
148 215 }
@@ -207,8 +274,35 @@
207 274 }
208 275
209 276
210 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 + /**
211 305 * Render popup style for order bump in elementor
212 306 * builder preview
213 307 *
214 308 * @since 2.0.3
@@ -258,26 +352,39 @@
258 352 foreach( $this->ob_settings as $key=> $settings ){
259 353
260 354 if( $settings['isEnabled'] && $settings['position'] == 'popup'){
261 355
356 + $this->mark_bump_render_instance( $checkout_id, $key );
357 +
262 358 if( $settings['isEnabled'] === 'no' ){
263 359 continue;
264 360 }
361 +
362 + // Check conditional rules before displaying
363 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
364 + continue;
365 + }
366 +
265 367 if (isset($settings['product']) && $settings['product'] != '') {
266 368 if ( !empty($settings['selectedStyle']) ) {
267 369
268 370 ob_start();
269 371 if ( $settings['position'] == 'popup' ) {
372 + $is_editor = false;
270 373
271 - if(Wpfnl_functions::is_elementor_active()) {
272 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
273 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
274 - } else {
275 - $order_bump_settings = $settings;
276 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
374 + if ( Wpfnl_functions::is_elementor_active() ) {
375 + if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) {
376 + $is_editor = true;
277 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>';
278 384 } else {
279 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
385 + $order_bump_settings = $settings;
386 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
280 387 }
281 388 } else {
282 389 $order_bump_settings = $settings;
283 390 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -311,8 +418,12 @@
311 418 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
312 419 $checkout_id = intval( $_POST['post_id'] );
313 420 }
314 421
422 + if( !$checkout_id ){
423 + $checkout_id = $this->checkout_id;
424 + }
425 +
315 426 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
316 427 if ( ! empty( $_POST['order_bump_data'] ) ) {
317 428 $settings = $_POST['order_bump_data'];
318 429 } else {
@@ -324,24 +435,37 @@
324 435
325 436 foreach( $this->ob_settings as $key=> $settings ){
326 437
327 438 if( $settings['isEnabled'] && $settings['position'] == 'before-checkout'){
439 + $this->mark_bump_render_instance( $checkout_id, $key );
328 440 if( $settings['isEnabled'] === 'no' ){
329 441 continue;
330 442 }
443 +
444 + // Check conditional rules before displaying
445 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
446 + continue;
447 + }
448 +
331 449 if (isset($settings['product']) && $settings['product'] != '') {
332 450 if ( !empty($settings['selectedStyle']) ) {
333 451 ob_start();
334 452 if ( $settings['position'] == 'popup' ) {
335 - if(Wpfnl_functions::is_elementor_active()) {
336 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
337 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
338 - } else {
339 - $order_bump_settings = $settings;
340 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
341 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>';
342 465 } else {
343 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
466 + $order_bump_settings = $settings;
467 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
344 468 }
345 469 } else {
346 470 $order_bump_settings = $settings;
347 471 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -377,8 +501,11 @@
377 501 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
378 502 $checkout_id = intval( $_POST['post_id'] );
379 503 }
380 504
505 + if( !$checkout_id ){
506 + $checkout_id = $this->checkout_id;
507 + }
381 508
382 509 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
383 510 if ( ! empty( $_POST['order_bump_data'] ) ) {
384 511 $settings = $_POST['order_bump_data'];
@@ -389,24 +516,37 @@
389 516 $type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true);
390 517 foreach( $this->ob_settings as $key=> $settings ){
391 518
392 519 if( $settings['isEnabled'] && $settings['position'] == 'before-lms-order'){
520 + $this->mark_bump_render_instance( $checkout_id, $key );
393 521 if( $settings['isEnabled'] === 'no' ){
394 522 continue;
395 523 }
524 +
525 + // Check conditional rules before displaying
526 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
527 + continue;
528 + }
529 +
396 530 if (isset($settings['product']) && $settings['product'] != '') {
397 531 if ( !empty($settings['selectedStyle']) ) {
398 532 ob_start();
399 533 if ( $settings['position'] == 'popup' ) {
400 - if(Wpfnl_functions::is_elementor_active()) {
401 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
402 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
403 - }else {
404 - $order_bump_settings = $settings;
405 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
406 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>';
407 546 } else {
408 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
547 + $order_bump_settings = $settings;
548 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
409 549 }
410 550 } else {
411 551 $order_bump_settings = $settings;
412 552 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -442,9 +582,11 @@
442 582 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
443 583 $checkout_id = intval( $_POST['post_id'] );
444 584 }
445 585
446 -
586 + if( !$checkout_id ){
587 + $checkout_id = $this->checkout_id;
588 + }
447 589 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
448 590 if ( ! empty( $_POST['order_bump_data'] ) ) {
449 591 $settings = $_POST['order_bump_data'];
450 592 } else {
@@ -455,24 +597,37 @@
455 597 $type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true);
456 598 foreach( $this->ob_settings as $key=> $settings ){
457 599
458 600 if( $settings['isEnabled'] && $settings['position'] == 'after-lms-order'){
601 + $this->mark_bump_render_instance( $checkout_id, $key );
459 602 if( $settings['isEnabled'] === 'no' ){
460 603 continue;
461 604 }
605 +
606 + // Check conditional rules before displaying
607 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
608 + continue;
609 + }
610 +
462 611 if (isset($settings['product']) && $settings['product'] != '') {
463 612 if ( !empty($settings['selectedStyle']) ) {
464 613 ob_start();
465 614 if ( $settings['position'] == 'popup' ) {
466 - if(Wpfnl_functions::is_elementor_active()) {
467 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
468 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
469 - } else {
470 - $order_bump_settings = $settings;
471 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
472 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>';
473 627 } else {
474 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
628 + $order_bump_settings = $settings;
629 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
475 630 }
476 631 } else {
477 632 $order_bump_settings = $settings;
478 633 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -508,9 +663,11 @@
508 663 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
509 664 $checkout_id = intval( $_POST['post_id'] );
510 665 }
511 666
512 -
667 + if( !$checkout_id ){
668 + $checkout_id = $this->checkout_id;
669 + }
513 670 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
514 671 if ( ! empty( $_POST['order_bump_data'] ) ) {
515 672 $settings = $_POST['order_bump_data'];
516 673 } else {
@@ -520,25 +677,38 @@
520 677 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
521 678
522 679 foreach( $this->ob_settings as $key=> $settings ){
523 680
524 - if( $settings['isEnabled'] && $settings['position'] == 'before-payment'){
681 + if( $settings['isEnabled'] && $settings['position'] == 'before-payment'){
682 + $this->mark_bump_render_instance( $checkout_id, $key );
525 683 if( $settings['isEnabled'] === 'no' ){
526 684 continue;
527 685 }
686 +
687 + // Check conditional rules before displaying
688 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
689 + continue;
690 + }
691 +
528 692 if (isset($settings['product']) && $settings['product'] != '') {
529 693 if ( !empty($settings['selectedStyle']) ) {
530 694 ob_start();
531 695 if ( $settings['position'] == 'popup' ) {
532 - if(Wpfnl_functions::is_elementor_active()) {
533 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
534 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
535 - } else {
536 - $order_bump_settings = $settings;
537 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
538 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>';
539 708 } else {
540 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
709 + $order_bump_settings = $settings;
710 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
541 711 }
542 712 } else {
543 713 $order_bump_settings = $settings;
544 714 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -574,9 +744,11 @@
574 744 $checkout_id = $post->ID;
575 745 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
576 746 $checkout_id = intval( $_POST['post_id'] );
577 747 }
578 -
748 + if( !$checkout_id ){
749 + $checkout_id = $this->checkout_id;
750 + }
579 751 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
580 752 if ( ! empty( $_POST['order_bump_data'] ) ) {
581 753 $settings = $_POST['order_bump_data'];
582 754 } else {
@@ -587,25 +759,38 @@
587 759 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
588 760
589 761 foreach( $this->ob_settings as $key=> $settings ){
590 762
591 - if( $settings['isEnabled'] && $settings['position'] == 'after-payment'){
763 + if( $settings['isEnabled'] && $settings['position'] == 'after-payment'){
764 + $this->mark_bump_render_instance( $checkout_id, $key );
592 765 if( $settings['isEnabled'] === 'no' ){
593 766 continue;
594 767 }
768 +
769 + // Check conditional rules before displaying
770 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
771 + continue;
772 + }
773 +
595 774 if (isset($settings['product']) && $settings['product'] != '') {
596 775 if ( !empty($settings['selectedStyle']) ) {
597 776 ob_start();
598 777 if ( $settings['position'] == 'popup' ) {
599 - if(Wpfnl_functions::is_elementor_active()) {
600 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
601 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
602 - } else {
603 - $order_bump_settings = $settings;
604 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
605 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>';
606 790 } else {
607 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
791 + $order_bump_settings = $settings;
792 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
608 793 }
609 794 } else {
610 795 $order_bump_settings = $settings;
611 796 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -641,10 +826,12 @@
641 826 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
642 827 $checkout_id = intval( $_POST['post_id'] );
643 828 }
644 829
830 + if( !$checkout_id ){
831 + $checkout_id = $this->checkout_id;
832 + }
645 833
646 -
647 834 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
648 835 if ( ! empty( $_POST['order_bump_data'] ) ) {
649 836 $settings = $_POST['order_bump_data'];
650 837 } else {
@@ -655,24 +842,35 @@
655 842 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
656 843
657 844 foreach( $this->ob_settings as $key=> $settings ){
658 845 if( $settings['isEnabled'] && $settings['position'] == 'after-customer-details'){
846 + $this->mark_bump_render_instance( $checkout_id, $key );
659 847 if( $settings['isEnabled'] === 'no' ){
660 848 continue;
661 849 }
850 + // Check conditional rules before displaying
851 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
852 + continue;
853 + }
662 854 if (isset($settings['product']) && $settings['product'] != '') {
663 855 if ( !empty($settings['selectedStyle']) ) {
664 856 ob_start();
665 857 if ( $settings['position'] == 'popup' ) {
666 - if(Wpfnl_functions::is_elementor_active()) {
667 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
668 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
669 - } else {
670 - $order_bump_settings = $settings;
671 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
672 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>';
673 870 } else {
674 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
871 + $order_bump_settings = $settings;
872 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
675 873 }
676 874 } else {
677 875 $order_bump_settings = $settings;
678 876 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -708,9 +906,13 @@
708 906 $checkout_id = $post->ID;
709 907 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
710 908 $checkout_id = intval( $_POST['post_id'] );
711 909 }
712 -
910 +
911 + if( !$checkout_id ){
912 + $checkout_id = $this->checkout_id;
913 + }
914 +
713 915 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
714 916 if ( ! empty( $_POST['order_bump_data'] ) ) {
715 917 $settings = $_POST['order_bump_data'];
716 918 } else {
@@ -722,26 +924,38 @@
722 924 foreach( $this->ob_settings as $key=> $settings ){
723 925
724 926 if( $settings['isEnabled'] && $settings['position'] == 'after-order'){
725 927
928 + $this->mark_bump_render_instance( $checkout_id, $key );
726 929
727 930 if( $settings['isEnabled'] === 'no' ){
728 931 continue;
729 932 }
730 933
934 + // Check conditional rules before displaying
935 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
936 + continue;
937 + }
938 +
731 939 if (isset($settings['product']) && $settings['product'] != '') {
732 940 if ( !empty($settings['selectedStyle']) ) {
733 941 ob_start();
734 942 if ( $settings['position'] == 'popup' ) {
735 - if(Wpfnl_functions::is_elementor_active()) {
736 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
737 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
738 - } else {
739 - $order_bump_settings = $settings;
740 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
741 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>';
742 955 } else {
743 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
956 + $order_bump_settings = $settings;
957 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
744 958 }
745 959 } else {
746 960 $order_bump_settings = $settings;
747 961 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
@@ -779,8 +993,12 @@
779 993 } elseif ( is_admin() && isset( $_POST['post_id'] ) ) {
780 994 $checkout_id = intval( $_POST['post_id'] );
781 995 }
782 996
997 + if( !$checkout_id ){
998 + $checkout_id = $this->checkout_id;
999 + }
1000 +
783 1001 if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) {
784 1002 if ( ! empty( $_POST['order_bump_data'] ) ) {
785 1003 $settings = $_POST['order_bump_data'];
786 1004 } else {
@@ -792,25 +1010,37 @@
792 1010
793 1011 foreach( $this->ob_settings as $key=> $settings ){
794 1012
795 1013 if( $settings['isEnabled'] && $settings['position'] == 'before-order'){
1014 + $this->mark_bump_render_instance( $checkout_id, $key );
796 1015 if( $settings['isEnabled'] === 'no' ){
797 1016 continue;
798 1017 }
799 1018
1019 + // Check conditional rules before displaying
1020 + if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) {
1021 + continue;
1022 + }
1023 +
800 1024 if (isset($settings['product']) && $settings['product'] != '') {
801 1025 if ( !empty($settings['selectedStyle']) ) {
802 1026 ob_start();
803 1027 if ( $settings['position'] == 'popup' ) {
804 - if(Wpfnl_functions::is_elementor_active()) {
805 - if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) {
806 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
807 - } else {
808 - $order_bump_settings = $settings;
809 - require_once WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
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;
810 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>';
811 1040 } else {
812 - echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>';
1041 + $order_bump_settings = $settings;
1042 + require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';
813 1043 }
814 1044 } else {
815 1045 $order_bump_settings = $settings;
816 1046 require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php';