| 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 |
public function __construct() { |
| 25 |
|
| 26 |
add_action( 'woocommerce_checkout_after_order_review', array( $this, 'add_order_bump_hidden_fields' ), 99 ); |
| 27 |
add_action( 'wpfunnels/elementor_render_order_bump', array( $this, 'load_elementor_actions' ), 9999, 2 ); |
| 28 |
add_action( 'wpfunnels/bricks_render_order_bump', array( $this, 'load_elementor_actions' ), 9999, 2 ); |
| 29 |
add_action( 'wpfunnels/gb_render_order_bump_ajax', array( $this, 'load_gb_actions' ), 10, 2 ); |
| 30 |
add_action( 'wpfunnels/before_checkout_form', array( $this, 'load_actions' ), 10, 2 ); |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function add_order_bump_hidden_fields() { |
| 37 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 38 |
|
| 39 |
$is_order_bump_enabled = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump'); |
| 40 |
|
| 41 |
$this->ob_settings = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta()); |
| 42 |
foreach( $this->ob_settings as $key=>$settings ){ |
| 43 |
if ( $settings['isEnabled'] ) { |
| 44 |
echo '<input type="hidden" name="_wpfunnels_order_bump_product_'.$key.'" value="">'; |
| 45 |
echo '<input type="hidden" name="_wpfunnels_order_bump_clicked" value="">'; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
public function load_actions( $checkout_id, $settings = array() ) { |
| 52 |
if( !function_exists( 'is_plugin_active' ) ) { |
| 53 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 54 |
if( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 55 |
if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 56 |
return false; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
else { |
| 61 |
if( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 62 |
if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 63 |
return false; |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 69 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 70 |
$this->ob_settings = $checkout_meta->get_checkout_meta_value( $checkout_id, 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta() ); |
| 71 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id ); |
| 72 |
|
| 73 |
$this->trigger_ob_actions(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
/** |
| 79 |
* Load elementor action for order bump preview |
| 80 |
* |
| 81 |
* @param $checkout_id |
| 82 |
* @param $settings |
| 83 |
* |
| 84 |
* @return void |
| 85 |
* @since 2.0.4 |
| 86 |
*/ |
| 87 |
public function load_elementor_actions( $checkout_id, $settings ) { |
| 88 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 89 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $settings, $funnel_id, $checkout_id ); |
| 90 |
$this->checkout_id = $checkout_id; |
| 91 |
$this->trigger_ob_actions(); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
/** |
| 96 |
* Load action hooks for order bump render |
| 97 |
* |
| 98 |
* @param $checkout_id |
| 99 |
* @param $ob_settings |
| 100 |
* |
| 101 |
* @return void |
| 102 |
* |
| 103 |
* @since 2.0.4 |
| 104 |
*/ |
| 105 |
public function load_gb_actions( $checkout_id, $ob_settings ) { |
| 106 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 107 |
$this->ob_settings = $ob_settings; |
| 108 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id ); |
| 109 |
$this->trigger_ob_actions(); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
/** |
| 115 |
* Trigger WC action for order bump |
| 116 |
* |
| 117 |
* @return void |
| 118 |
* |
| 119 |
* @since 2.0.4 |
| 120 |
*/ |
| 121 |
private function trigger_ob_actions() { |
| 122 |
if( is_array( $this->ob_settings ) ) { |
| 123 |
foreach( $this->ob_settings as $key => $settings ) { |
| 124 |
$this->current_ob_settings = $settings; |
| 125 |
$position = $this->get_order_bump_attribute( $settings, 'position' ); |
| 126 |
$is_enabled = $this->get_order_bump_attribute( $settings, 'isEnabled' ); |
| 127 |
|
| 128 |
if( 'yes' === $is_enabled || 1 === (int)$is_enabled || 'true' == $is_enabled ) { |
| 129 |
$is_enabled = true; |
| 130 |
} |
| 131 |
elseif( 'no' === $is_enabled || 0 === (int)$is_enabled || '' === $is_enabled ) { |
| 132 |
$is_enabled = false; |
| 133 |
} |
| 134 |
|
| 135 |
if( !$position ) { |
| 136 |
return; |
| 137 |
} |
| 138 |
if( !$is_enabled ) { |
| 139 |
continue; |
| 140 |
} |
| 141 |
|
| 142 |
if( $position === 'before-checkout' ) { |
| 143 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump_before_checkout_form' ], 10 ); |
| 144 |
} |
| 145 |
elseif( $position === 'after-order' ) { |
| 146 |
add_action( 'wpfunnels/after_order_total', [ $this, 'render_order_bump_after_order' ], 10 ); |
| 147 |
} |
| 148 |
elseif( $position === 'before-order' ) { |
| 149 |
add_action( 'woocommerce_review_order_before_cart_contents', [ $this, 'render_order_bump_before_order' ], 10 ); |
| 150 |
} |
| 151 |
elseif( $position === 'after-customer-details' ) { |
| 152 |
add_action( 'woocommerce_after_order_notes', [ $this, 'render_order_bump_after_customer_details' ], 10 ); |
| 153 |
} |
| 154 |
elseif( $position === 'before-payment' ) { |
| 155 |
add_action( 'woocommerce_review_order_before_payment', [ $this, 'render_order_bump_before_payment' ], 10 ); |
| 156 |
} |
| 157 |
elseif( $position === 'after-payment' ) { |
| 158 |
add_action( 'woocommerce_review_order_after_payment', [ $this, 'render_order_bump_after_payment' ], 10 ); |
| 159 |
} |
| 160 |
elseif( $position === 'after-lms-order' ) { |
| 161 |
add_action( 'wpfunnels/after_lms_order_deatils', [ $this, 'render_order_bump_after_lms_order_deatils' ], 10 ); |
| 162 |
} |
| 163 |
elseif( $position === 'before-lms-order' ) { |
| 164 |
add_action( 'wpfunnels/before_lms_order_deatils', [ $this, 'render_order_bump_before_lms_order_deatils' ], 10 ); |
| 165 |
} |
| 166 |
elseif( $position === 'popup' ) { |
| 167 |
$this->ob_settings[ $key ][ 'selectedStyle' ] = 'popup'; |
| 168 |
$this->render_popup_in_elementor_editor(); |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
/** |
| 178 |
* Add order bump extra meta data |
| 179 |
* to main settings data |
| 180 |
* |
| 181 |
* @param $ob_settings |
| 182 |
* @param $funnel_id |
| 183 |
* @param $checkout_id |
| 184 |
* |
| 185 |
* @return array |
| 186 |
*/ |
| 187 |
public function add_extra_ob_data( $ob_settings, $funnel_id, $checkout_id ) { |
| 188 |
$ob_settings['step_id'] = $checkout_id; |
| 189 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 190 |
$main_product_ids = $checkout_meta->get_main_product_ids( $funnel_id, $checkout_id ); |
| 191 |
$ob_settings['main_products'] = $main_product_ids; |
| 192 |
return $ob_settings; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
/** |
| 197 |
* Get order bump attribute from order bump settings data |
| 198 |
* |
| 199 |
* @param $order_bump_data |
| 200 |
* @param $key |
| 201 |
* |
| 202 |
* @return bool|mixed |
| 203 |
*/ |
| 204 |
private function get_order_bump_attribute( $order_bump_data, $key ) { |
| 205 |
if( !isset($order_bump_data[$key]) ) { |
| 206 |
return false; |
| 207 |
} |
| 208 |
return $order_bump_data[$key]; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
/** |
| 213 |
* Render popup style for order bump in elementor |
| 214 |
* builder preview |
| 215 |
* |
| 216 |
* @since 2.0.3 |
| 217 |
*/ |
| 218 |
public function render_popup_in_elementor_editor() { |
| 219 |
if( Wpfnl_functions::is_elementor_active() ) { |
| 220 |
if( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 221 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 222 |
} |
| 223 |
else { |
| 224 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 225 |
} |
| 226 |
} |
| 227 |
else { |
| 228 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
/** |
| 234 |
* Render order bump markup |
| 235 |
* |
| 236 |
* @since 2.0.3 |
| 237 |
*/ |
| 238 |
public function render_order_bump() { |
| 239 |
|
| 240 |
global $post; |
| 241 |
$checkout_id = 0; |
| 242 |
$output = ''; |
| 243 |
if ( $post ) { |
| 244 |
$checkout_id = $post->ID; |
| 245 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 246 |
$checkout_id = intval( $_POST['post_id'] ); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 251 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 252 |
$settings = $_POST['order_bump_data']; |
| 253 |
} else { |
| 254 |
$settings = $this->ob_settings; |
| 255 |
} |
| 256 |
|
| 257 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 258 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 259 |
|
| 260 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 261 |
|
| 262 |
if( $settings['isEnabled'] && $settings['position'] == 'popup'){ |
| 263 |
|
| 264 |
if( $settings['isEnabled'] === 'no' ){ |
| 265 |
continue; |
| 266 |
} |
| 267 |
|
| 268 |
// Check conditional rules before displaying |
| 269 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 270 |
continue; |
| 271 |
} |
| 272 |
|
| 273 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 274 |
if ( !empty($settings['selectedStyle']) ) { |
| 275 |
|
| 276 |
ob_start(); |
| 277 |
if ( $settings['position'] == 'popup' ) { |
| 278 |
$is_editor = false; |
| 279 |
|
| 280 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 281 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 282 |
$is_editor = true; |
| 283 |
} |
| 284 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 285 |
$is_editor = true; |
| 286 |
} |
| 287 |
|
| 288 |
if ( $is_editor ) { |
| 289 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 290 |
} else { |
| 291 |
$order_bump_settings = $settings; |
| 292 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 293 |
} |
| 294 |
} else { |
| 295 |
$order_bump_settings = $settings; |
| 296 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 297 |
} |
| 298 |
$output .= ob_get_clean(); |
| 299 |
} |
| 300 |
} |
| 301 |
else { |
| 302 |
wc_clear_notices(); |
| 303 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 304 |
} |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
echo $output; |
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* Render order bump markup |
| 314 |
* |
| 315 |
* @since 2.0.3 |
| 316 |
*/ |
| 317 |
public function render_order_bump_before_checkout_form() { |
| 318 |
|
| 319 |
global $post; |
| 320 |
$checkout_id = 0; |
| 321 |
$output = ''; |
| 322 |
if ( $post ) { |
| 323 |
$checkout_id = $post->ID; |
| 324 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 325 |
$checkout_id = intval( $_POST['post_id'] ); |
| 326 |
} |
| 327 |
|
| 328 |
if( !$checkout_id ){ |
| 329 |
$checkout_id = $this->checkout_id; |
| 330 |
} |
| 331 |
|
| 332 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 333 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 334 |
$settings = $_POST['order_bump_data']; |
| 335 |
} else { |
| 336 |
$settings = $this->ob_settings; |
| 337 |
} |
| 338 |
|
| 339 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 340 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 341 |
|
| 342 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 343 |
|
| 344 |
if( $settings['isEnabled'] && $settings['position'] == 'before-checkout'){ |
| 345 |
if( $settings['isEnabled'] === 'no' ){ |
| 346 |
continue; |
| 347 |
} |
| 348 |
|
| 349 |
// Check conditional rules before displaying |
| 350 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 351 |
continue; |
| 352 |
} |
| 353 |
|
| 354 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 355 |
if ( !empty($settings['selectedStyle']) ) { |
| 356 |
ob_start(); |
| 357 |
if ( $settings['position'] == 'popup' ) { |
| 358 |
$is_editor = false; |
| 359 |
|
| 360 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 361 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 362 |
$is_editor = true; |
| 363 |
} |
| 364 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 365 |
$is_editor = true; |
| 366 |
} |
| 367 |
|
| 368 |
if ( $is_editor ) { |
| 369 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 370 |
} else { |
| 371 |
$order_bump_settings = $settings; |
| 372 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 373 |
} |
| 374 |
} else { |
| 375 |
$order_bump_settings = $settings; |
| 376 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 377 |
} |
| 378 |
$output .= ob_get_clean(); |
| 379 |
} |
| 380 |
} |
| 381 |
else { |
| 382 |
wc_clear_notices(); |
| 383 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
} |
| 389 |
|
| 390 |
echo $output; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
/** |
| 395 |
* Render order bump markup |
| 396 |
* |
| 397 |
* @since 2.0.3 |
| 398 |
*/ |
| 399 |
public function render_order_bump_before_lms_order_deatils() { |
| 400 |
|
| 401 |
global $post; |
| 402 |
$checkout_id = 0; |
| 403 |
$output = ''; |
| 404 |
if ( $post ) { |
| 405 |
$checkout_id = $post->ID; |
| 406 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 407 |
$checkout_id = intval( $_POST['post_id'] ); |
| 408 |
} |
| 409 |
|
| 410 |
if( !$checkout_id ){ |
| 411 |
$checkout_id = $this->checkout_id; |
| 412 |
} |
| 413 |
|
| 414 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 415 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 416 |
$settings = $_POST['order_bump_data']; |
| 417 |
} else { |
| 418 |
$settings = $this->ob_settings; |
| 419 |
} |
| 420 |
$funnel_id = get_post_meta($checkout_id,'_funnel_id',true); |
| 421 |
$type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true); |
| 422 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 423 |
|
| 424 |
if( $settings['isEnabled'] && $settings['position'] == 'before-lms-order'){ |
| 425 |
if( $settings['isEnabled'] === 'no' ){ |
| 426 |
continue; |
| 427 |
} |
| 428 |
|
| 429 |
// Check conditional rules before displaying |
| 430 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 431 |
continue; |
| 432 |
} |
| 433 |
|
| 434 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 435 |
if ( !empty($settings['selectedStyle']) ) { |
| 436 |
ob_start(); |
| 437 |
if ( $settings['position'] == 'popup' ) { |
| 438 |
$is_editor = false; |
| 439 |
|
| 440 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 441 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 442 |
$is_editor = true; |
| 443 |
} |
| 444 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 445 |
$is_editor = true; |
| 446 |
} |
| 447 |
|
| 448 |
if ( $is_editor ) { |
| 449 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 450 |
} else { |
| 451 |
$order_bump_settings = $settings; |
| 452 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 453 |
} |
| 454 |
} else { |
| 455 |
$order_bump_settings = $settings; |
| 456 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 457 |
} |
| 458 |
$output .= ob_get_clean(); |
| 459 |
} |
| 460 |
} |
| 461 |
else { |
| 462 |
wc_clear_notices(); |
| 463 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
} |
| 469 |
|
| 470 |
echo $output; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
/** |
| 475 |
* Render order bump markup |
| 476 |
* |
| 477 |
* @since 2.0.3 |
| 478 |
*/ |
| 479 |
public function render_order_bump_after_lms_order_deatils() { |
| 480 |
|
| 481 |
global $post; |
| 482 |
$checkout_id = 0; |
| 483 |
$output = ''; |
| 484 |
if ( $post ) { |
| 485 |
$checkout_id = $post->ID; |
| 486 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 487 |
$checkout_id = intval( $_POST['post_id'] ); |
| 488 |
} |
| 489 |
|
| 490 |
if( !$checkout_id ){ |
| 491 |
$checkout_id = $this->checkout_id; |
| 492 |
} |
| 493 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 494 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 495 |
$settings = $_POST['order_bump_data']; |
| 496 |
} else { |
| 497 |
$settings = $this->ob_settings; |
| 498 |
} |
| 499 |
|
| 500 |
$funnel_id = get_post_meta($checkout_id,'_funnel_id',true); |
| 501 |
$type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true); |
| 502 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 503 |
|
| 504 |
if( $settings['isEnabled'] && $settings['position'] == 'after-lms-order'){ |
| 505 |
if( $settings['isEnabled'] === 'no' ){ |
| 506 |
continue; |
| 507 |
} |
| 508 |
|
| 509 |
// Check conditional rules before displaying |
| 510 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 511 |
continue; |
| 512 |
} |
| 513 |
|
| 514 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 515 |
if ( !empty($settings['selectedStyle']) ) { |
| 516 |
ob_start(); |
| 517 |
if ( $settings['position'] == 'popup' ) { |
| 518 |
$is_editor = false; |
| 519 |
|
| 520 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 521 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 522 |
$is_editor = true; |
| 523 |
} |
| 524 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 525 |
$is_editor = true; |
| 526 |
} |
| 527 |
|
| 528 |
if ( $is_editor ) { |
| 529 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 530 |
} else { |
| 531 |
$order_bump_settings = $settings; |
| 532 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 533 |
} |
| 534 |
} else { |
| 535 |
$order_bump_settings = $settings; |
| 536 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 537 |
} |
| 538 |
$output .= ob_get_clean(); |
| 539 |
} |
| 540 |
} |
| 541 |
else { |
| 542 |
wc_clear_notices(); |
| 543 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 544 |
} |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
} |
| 549 |
|
| 550 |
echo $output; |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* Render order bump markup |
| 555 |
* |
| 556 |
* @since 2.0.3 |
| 557 |
*/ |
| 558 |
public function render_order_bump_before_payment() { |
| 559 |
|
| 560 |
|
| 561 |
global $post; |
| 562 |
$checkout_id = 0; |
| 563 |
$output = ''; |
| 564 |
if ( $post ) { |
| 565 |
$checkout_id = $post->ID; |
| 566 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 567 |
$checkout_id = intval( $_POST['post_id'] ); |
| 568 |
} |
| 569 |
|
| 570 |
if( !$checkout_id ){ |
| 571 |
$checkout_id = $this->checkout_id; |
| 572 |
} |
| 573 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 574 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 575 |
$settings = $_POST['order_bump_data']; |
| 576 |
} else { |
| 577 |
$settings = $this->ob_settings; |
| 578 |
} |
| 579 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 580 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 581 |
|
| 582 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 583 |
|
| 584 |
if( $settings['isEnabled'] && $settings['position'] == 'before-payment'){ |
| 585 |
if( $settings['isEnabled'] === 'no' ){ |
| 586 |
continue; |
| 587 |
} |
| 588 |
|
| 589 |
// Check conditional rules before displaying |
| 590 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 591 |
continue; |
| 592 |
} |
| 593 |
|
| 594 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 595 |
if ( !empty($settings['selectedStyle']) ) { |
| 596 |
ob_start(); |
| 597 |
if ( $settings['position'] == 'popup' ) { |
| 598 |
$is_editor = false; |
| 599 |
|
| 600 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 601 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 602 |
$is_editor = true; |
| 603 |
} |
| 604 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 605 |
$is_editor = true; |
| 606 |
} |
| 607 |
|
| 608 |
if ( $is_editor ) { |
| 609 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 610 |
} else { |
| 611 |
$order_bump_settings = $settings; |
| 612 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 613 |
} |
| 614 |
} else { |
| 615 |
$order_bump_settings = $settings; |
| 616 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 617 |
} |
| 618 |
$output .= ob_get_clean(); |
| 619 |
} |
| 620 |
} |
| 621 |
else { |
| 622 |
wc_clear_notices(); |
| 623 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 624 |
} |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
} |
| 629 |
|
| 630 |
echo $output; |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
/** |
| 635 |
* Render order bump markup |
| 636 |
* |
| 637 |
* @since 2.0.3 |
| 638 |
*/ |
| 639 |
public function render_order_bump_after_payment() { |
| 640 |
|
| 641 |
global $post; |
| 642 |
$checkout_id = 0; |
| 643 |
$output = ''; |
| 644 |
|
| 645 |
if ( $post ) { |
| 646 |
$checkout_id = $post->ID; |
| 647 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 648 |
$checkout_id = intval( $_POST['post_id'] ); |
| 649 |
} |
| 650 |
if( !$checkout_id ){ |
| 651 |
$checkout_id = $this->checkout_id; |
| 652 |
} |
| 653 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 654 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 655 |
$settings = $_POST['order_bump_data']; |
| 656 |
} else { |
| 657 |
$settings = $this->ob_settings; |
| 658 |
} |
| 659 |
|
| 660 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 661 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 662 |
|
| 663 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 664 |
|
| 665 |
if( $settings['isEnabled'] && $settings['position'] == 'after-payment'){ |
| 666 |
if( $settings['isEnabled'] === 'no' ){ |
| 667 |
continue; |
| 668 |
} |
| 669 |
|
| 670 |
// Check conditional rules before displaying |
| 671 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 672 |
continue; |
| 673 |
} |
| 674 |
|
| 675 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 676 |
if ( !empty($settings['selectedStyle']) ) { |
| 677 |
ob_start(); |
| 678 |
if ( $settings['position'] == 'popup' ) { |
| 679 |
$is_editor = false; |
| 680 |
|
| 681 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 682 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 683 |
$is_editor = true; |
| 684 |
} |
| 685 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 686 |
$is_editor = true; |
| 687 |
} |
| 688 |
|
| 689 |
if ( $is_editor ) { |
| 690 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 691 |
} else { |
| 692 |
$order_bump_settings = $settings; |
| 693 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 694 |
} |
| 695 |
} else { |
| 696 |
$order_bump_settings = $settings; |
| 697 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 698 |
} |
| 699 |
$output .= ob_get_clean(); |
| 700 |
} |
| 701 |
} |
| 702 |
else { |
| 703 |
wc_clear_notices(); |
| 704 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 705 |
} |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
} |
| 710 |
|
| 711 |
echo $output; |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
/** |
| 716 |
* Render order bump markup |
| 717 |
* |
| 718 |
* @since 2.0.3 |
| 719 |
*/ |
| 720 |
public function render_order_bump_after_customer_details() { |
| 721 |
|
| 722 |
global $post; |
| 723 |
$checkout_id = 0; |
| 724 |
$output = ''; |
| 725 |
if ( $post ) { |
| 726 |
$checkout_id = $post->ID; |
| 727 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 728 |
$checkout_id = intval( $_POST['post_id'] ); |
| 729 |
} |
| 730 |
|
| 731 |
if( !$checkout_id ){ |
| 732 |
$checkout_id = $this->checkout_id; |
| 733 |
} |
| 734 |
|
| 735 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 736 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 737 |
$settings = $_POST['order_bump_data']; |
| 738 |
} else { |
| 739 |
$settings = $this->ob_settings; |
| 740 |
} |
| 741 |
|
| 742 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 743 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 744 |
|
| 745 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 746 |
if( $settings['isEnabled'] && $settings['position'] == 'after-customer-details'){ |
| 747 |
if( $settings['isEnabled'] === 'no' ){ |
| 748 |
continue; |
| 749 |
} |
| 750 |
// Check conditional rules before displaying |
| 751 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 752 |
continue; |
| 753 |
} |
| 754 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 755 |
if ( !empty($settings['selectedStyle']) ) { |
| 756 |
ob_start(); |
| 757 |
if ( $settings['position'] == 'popup' ) { |
| 758 |
$is_editor = false; |
| 759 |
|
| 760 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 761 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 762 |
$is_editor = true; |
| 763 |
} |
| 764 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 765 |
$is_editor = true; |
| 766 |
} |
| 767 |
|
| 768 |
if ( $is_editor ) { |
| 769 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 770 |
} else { |
| 771 |
$order_bump_settings = $settings; |
| 772 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 773 |
} |
| 774 |
} else { |
| 775 |
$order_bump_settings = $settings; |
| 776 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 777 |
} |
| 778 |
$output .= ob_get_clean(); |
| 779 |
} |
| 780 |
} |
| 781 |
else { |
| 782 |
wc_clear_notices(); |
| 783 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 784 |
} |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
} |
| 789 |
|
| 790 |
echo $output; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
/** |
| 795 |
* Render order bump markup |
| 796 |
* |
| 797 |
* @since 2.0.3 |
| 798 |
*/ |
| 799 |
public function render_order_bump_after_order() { |
| 800 |
|
| 801 |
global $post; |
| 802 |
$checkout_id = 0; |
| 803 |
$output = ''; |
| 804 |
|
| 805 |
if ( $post ) { |
| 806 |
$checkout_id = $post->ID; |
| 807 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 808 |
$checkout_id = intval( $_POST['post_id'] ); |
| 809 |
} |
| 810 |
|
| 811 |
if( !$checkout_id ){ |
| 812 |
$checkout_id = $this->checkout_id; |
| 813 |
} |
| 814 |
|
| 815 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 816 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 817 |
$settings = $_POST['order_bump_data']; |
| 818 |
} else { |
| 819 |
$settings = $this->ob_settings; |
| 820 |
} |
| 821 |
|
| 822 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 823 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 824 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 825 |
|
| 826 |
if( $settings['isEnabled'] && $settings['position'] == 'after-order'){ |
| 827 |
|
| 828 |
|
| 829 |
if( $settings['isEnabled'] === 'no' ){ |
| 830 |
continue; |
| 831 |
} |
| 832 |
|
| 833 |
// Check conditional rules before displaying |
| 834 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 835 |
continue; |
| 836 |
} |
| 837 |
|
| 838 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 839 |
if ( !empty($settings['selectedStyle']) ) { |
| 840 |
ob_start(); |
| 841 |
if ( $settings['position'] == 'popup' ) { |
| 842 |
$is_editor = false; |
| 843 |
|
| 844 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 845 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 846 |
$is_editor = true; |
| 847 |
} |
| 848 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 849 |
$is_editor = true; |
| 850 |
} |
| 851 |
|
| 852 |
if ( $is_editor ) { |
| 853 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 854 |
} else { |
| 855 |
$order_bump_settings = $settings; |
| 856 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 857 |
} |
| 858 |
} else { |
| 859 |
$order_bump_settings = $settings; |
| 860 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 861 |
} |
| 862 |
$output .= ob_get_clean(); |
| 863 |
} |
| 864 |
} |
| 865 |
else { |
| 866 |
wc_clear_notices(); |
| 867 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 868 |
} |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
} |
| 873 |
|
| 874 |
echo $output; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
/** |
| 879 |
* Render order bump markup |
| 880 |
* |
| 881 |
* @since 2.0.3 |
| 882 |
*/ |
| 883 |
public function render_order_bump_before_order() { |
| 884 |
|
| 885 |
global $post; |
| 886 |
$checkout_id = 0; |
| 887 |
$output = ''; |
| 888 |
|
| 889 |
|
| 890 |
if ( $post ) { |
| 891 |
$checkout_id = $post->ID; |
| 892 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 893 |
$checkout_id = intval( $_POST['post_id'] ); |
| 894 |
} |
| 895 |
|
| 896 |
if( !$checkout_id ){ |
| 897 |
$checkout_id = $this->checkout_id; |
| 898 |
} |
| 899 |
|
| 900 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 901 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 902 |
$settings = $_POST['order_bump_data']; |
| 903 |
} else { |
| 904 |
$settings = $this->ob_settings; |
| 905 |
} |
| 906 |
|
| 907 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 908 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 909 |
|
| 910 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 911 |
|
| 912 |
if( $settings['isEnabled'] && $settings['position'] == 'before-order'){ |
| 913 |
if( $settings['isEnabled'] === 'no' ){ |
| 914 |
continue; |
| 915 |
} |
| 916 |
|
| 917 |
// Check conditional rules before displaying |
| 918 |
if ( ! Wpfnl_Order_Bump_Rules::should_display_order_bump( $settings ) ) { |
| 919 |
continue; |
| 920 |
} |
| 921 |
|
| 922 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 923 |
if ( !empty($settings['selectedStyle']) ) { |
| 924 |
ob_start(); |
| 925 |
if ( $settings['position'] == 'popup' ) { |
| 926 |
$is_editor = false; |
| 927 |
|
| 928 |
if ( Wpfnl_functions::is_elementor_active() ) { |
| 929 |
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 930 |
$is_editor = true; |
| 931 |
} |
| 932 |
} elseif ( is_admin() && ! wp_doing_ajax() ) { |
| 933 |
$is_editor = true; |
| 934 |
} |
| 935 |
|
| 936 |
if ( $is_editor ) { |
| 937 |
echo '<h5 style="margin-bottom: 15px;"><strong>' . __('To see the pop-up offer in action, please preview or view the page.', 'wpfnl') . '</strong></h5>'; |
| 938 |
} else { |
| 939 |
$order_bump_settings = $settings; |
| 940 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 941 |
} |
| 942 |
} else { |
| 943 |
$order_bump_settings = $settings; |
| 944 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 945 |
} |
| 946 |
$output .= ob_get_clean(); |
| 947 |
} |
| 948 |
} |
| 949 |
else { |
| 950 |
wc_clear_notices(); |
| 951 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 952 |
} |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
} |
| 957 |
|
| 958 |
echo $output; |
| 959 |
} |
| 960 |
} |