| 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 WPFunnels\Meta\Wpfnl_Default_Meta; |
| 10 |
use WPFunnels\Traits\SingletonTrait; |
| 11 |
use WPFunnels\Wpfnl_functions; |
| 12 |
|
| 13 |
class Wpfnl_Order_Bump_Action { |
| 14 |
|
| 15 |
use SingletonTrait; |
| 16 |
|
| 17 |
protected $ob_settings; |
| 18 |
protected $current_ob_settings; |
| 19 |
protected $selected_ob; |
| 20 |
|
| 21 |
public function __construct() { |
| 22 |
|
| 23 |
add_action( 'woocommerce_checkout_after_order_review', array( $this, 'add_order_bump_hidden_fields' ), 99 ); |
| 24 |
add_action( 'wpfunnels/elementor_render_order_bump', array( $this, 'load_elementor_actions' ), 9999, 2 ); |
| 25 |
add_action( 'wpfunnels/gb_render_order_bump_ajax', array( $this, 'load_gb_actions' ), 10, 2 ); |
| 26 |
add_action( 'wpfunnels/before_checkout_form', array( $this, 'load_actions' ), 10, 2 ); |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function add_order_bump_hidden_fields() { |
| 33 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 34 |
|
| 35 |
$is_order_bump_enabled = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump'); |
| 36 |
|
| 37 |
$this->ob_settings = $checkout_meta->get_checkout_meta_value(get_the_ID(), 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta()); |
| 38 |
foreach( $this->ob_settings as $key=>$settings ){ |
| 39 |
if ( $settings['isEnabled'] ) { |
| 40 |
echo '<input type="hidden" name="_wpfunnels_order_bump_product_'.$key.'" value="">'; |
| 41 |
echo '<input type="hidden" name="_wpfunnels_order_bump_clicked" value="">'; |
| 42 |
|
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
public function load_actions( $checkout_id, $settings = array() ) { |
| 51 |
if( !function_exists( 'is_plugin_active' ) ) { |
| 52 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 53 |
if( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 54 |
if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
else { |
| 60 |
if( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 61 |
if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 62 |
return false; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 68 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 69 |
$this->ob_settings = $checkout_meta->get_checkout_meta_value( $checkout_id, 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta() ); |
| 70 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id ); |
| 71 |
|
| 72 |
$this->trigger_ob_actions(); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* Load elementor action for order bump preview |
| 79 |
* |
| 80 |
* @param $checkout_id |
| 81 |
* @param $settings |
| 82 |
* |
| 83 |
* @return void |
| 84 |
* @since 2.0.4 |
| 85 |
*/ |
| 86 |
public function load_elementor_actions( $checkout_id, $settings ) { |
| 87 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 88 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $settings, $funnel_id, $checkout_id ); |
| 89 |
$this->trigger_ob_actions(); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
/** |
| 94 |
* Load action hooks for order bump render |
| 95 |
* |
| 96 |
* @param $checkout_id |
| 97 |
* @param $ob_settings |
| 98 |
* |
| 99 |
* @return void |
| 100 |
* |
| 101 |
* @since 2.0.4 |
| 102 |
*/ |
| 103 |
public function load_gb_actions( $checkout_id, $ob_settings ) { |
| 104 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 105 |
$this->ob_settings = $ob_settings; |
| 106 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id ); |
| 107 |
$this->trigger_ob_actions(); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
/** |
| 113 |
* Trigger WC action for order bump |
| 114 |
* |
| 115 |
* @return void |
| 116 |
* |
| 117 |
* @since 2.0.4 |
| 118 |
*/ |
| 119 |
private function trigger_ob_actions() { |
| 120 |
if( is_array( $this->ob_settings ) ) { |
| 121 |
foreach( $this->ob_settings as $key => $settings ) { |
| 122 |
$this->current_ob_settings = $settings; |
| 123 |
$position = $this->get_order_bump_attribute( $settings, 'position' ); |
| 124 |
$is_enabled = $this->get_order_bump_attribute( $settings, 'isEnabled' ); |
| 125 |
|
| 126 |
if( 'yes' === $is_enabled || 1 === (int)$is_enabled || 'true' == $is_enabled ) { |
| 127 |
$is_enabled = true; |
| 128 |
} |
| 129 |
elseif( 'no' === $is_enabled || 0 === (int)$is_enabled || '' === $is_enabled ) { |
| 130 |
$is_enabled = false; |
| 131 |
} |
| 132 |
|
| 133 |
if( !$position ) { |
| 134 |
return; |
| 135 |
} |
| 136 |
if( !$is_enabled ) { |
| 137 |
continue; |
| 138 |
} |
| 139 |
|
| 140 |
if( $position === 'before-checkout' ) { |
| 141 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump_before_checkout_form' ], 10 ); |
| 142 |
} |
| 143 |
elseif( $position === 'after-order' ) { |
| 144 |
add_action( 'woocommerce_review_order_after_cart_contents', [ $this, 'render_order_bump_after_order' ], 10 ); |
| 145 |
} |
| 146 |
elseif( $position === 'before-order' ) { |
| 147 |
add_action( 'woocommerce_review_order_before_cart_contents', [ $this, 'render_order_bump_before_order' ], 10 ); |
| 148 |
} |
| 149 |
elseif( $position === 'after-customer-details' ) { |
| 150 |
add_action( 'woocommerce_after_order_notes', [ $this, 'render_order_bump_after_customer_details' ], 10 ); |
| 151 |
} |
| 152 |
elseif( $position === 'before-payment' ) { |
| 153 |
add_action( 'woocommerce_review_order_before_payment', [ $this, 'render_order_bump_before_payment' ], 10 ); |
| 154 |
} |
| 155 |
elseif( $position === 'after-payment' ) { |
| 156 |
add_action( 'woocommerce_review_order_after_payment', [ $this, 'render_order_bump_after_payment' ], 10 ); |
| 157 |
} |
| 158 |
elseif( $position === 'after-lms-order' ) { |
| 159 |
add_action( 'wpfunnels/after_lms_order_deatils', [ $this, 'render_order_bump_after_lms_order_deatils' ], 10 ); |
| 160 |
} |
| 161 |
elseif( $position === 'before-lms-order' ) { |
| 162 |
add_action( 'wpfunnels/before_lms_order_deatils', [ $this, 'render_order_bump_before_lms_order_deatils' ], 10 ); |
| 163 |
} |
| 164 |
elseif( $position === 'popup' ) { |
| 165 |
$this->ob_settings[ $key ][ 'selectedStyle' ] = 'popup'; |
| 166 |
$this->render_popup_in_elementor_editor(); |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
/** |
| 176 |
* Add order bump extra meta data |
| 177 |
* to main settings data |
| 178 |
* |
| 179 |
* @param $ob_settings |
| 180 |
* @param $funnel_id |
| 181 |
* @param $checkout_id |
| 182 |
* |
| 183 |
* @return array |
| 184 |
*/ |
| 185 |
public function add_extra_ob_data( $ob_settings, $funnel_id, $checkout_id ) { |
| 186 |
$ob_settings['step_id'] = $checkout_id; |
| 187 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 188 |
$main_product_ids = $checkout_meta->get_main_product_ids( $funnel_id, $checkout_id ); |
| 189 |
$ob_settings['main_products'] = $main_product_ids; |
| 190 |
return $ob_settings; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
/** |
| 195 |
* Get order bump attribute from order bump settings data |
| 196 |
* |
| 197 |
* @param $order_bump_data |
| 198 |
* @param $key |
| 199 |
* |
| 200 |
* @return bool|mixed |
| 201 |
*/ |
| 202 |
private function get_order_bump_attribute( $order_bump_data, $key ) { |
| 203 |
if( !isset($order_bump_data[$key]) ) { |
| 204 |
return false; |
| 205 |
} |
| 206 |
return $order_bump_data[$key]; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
/** |
| 211 |
* Render popup style for order bump in elementor |
| 212 |
* builder preview |
| 213 |
* |
| 214 |
* @since 2.0.3 |
| 215 |
*/ |
| 216 |
public function render_popup_in_elementor_editor() { |
| 217 |
if( Wpfnl_functions::is_elementor_active() ) { |
| 218 |
if( \Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin() ) { |
| 219 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 220 |
} |
| 221 |
else { |
| 222 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 223 |
} |
| 224 |
} |
| 225 |
else { |
| 226 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
/** |
| 232 |
* Render order bump markup |
| 233 |
* |
| 234 |
* @since 2.0.3 |
| 235 |
*/ |
| 236 |
public function render_order_bump() { |
| 237 |
|
| 238 |
global $post; |
| 239 |
$checkout_id = 0; |
| 240 |
$output = ''; |
| 241 |
if ( $post ) { |
| 242 |
$checkout_id = $post->ID; |
| 243 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 244 |
$checkout_id = intval( $_POST['post_id'] ); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 249 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 250 |
$settings = $_POST['order_bump_data']; |
| 251 |
} else { |
| 252 |
$settings = $this->ob_settings; |
| 253 |
} |
| 254 |
|
| 255 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 256 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 257 |
|
| 258 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 259 |
|
| 260 |
if( $settings['isEnabled'] && $settings['position'] == 'popup'){ |
| 261 |
|
| 262 |
if( $settings['isEnabled'] === 'no' ){ |
| 263 |
continue; |
| 264 |
} |
| 265 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 266 |
if ( !empty($settings['selectedStyle']) ) { |
| 267 |
|
| 268 |
ob_start(); |
| 269 |
if ( $settings['position'] == 'popup' ) { |
| 270 |
|
| 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'; |
| 277 |
} |
| 278 |
} 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>'; |
| 280 |
} |
| 281 |
} else { |
| 282 |
$order_bump_settings = $settings; |
| 283 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 284 |
} |
| 285 |
$output .= ob_get_clean(); |
| 286 |
} |
| 287 |
} |
| 288 |
else { |
| 289 |
wc_clear_notices(); |
| 290 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
echo $output; |
| 297 |
} |
| 298 |
|
| 299 |
/** |
| 300 |
* Render order bump markup |
| 301 |
* |
| 302 |
* @since 2.0.3 |
| 303 |
*/ |
| 304 |
public function render_order_bump_before_checkout_form() { |
| 305 |
|
| 306 |
global $post; |
| 307 |
$checkout_id = 0; |
| 308 |
$output = ''; |
| 309 |
if ( $post ) { |
| 310 |
$checkout_id = $post->ID; |
| 311 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 312 |
$checkout_id = intval( $_POST['post_id'] ); |
| 313 |
} |
| 314 |
|
| 315 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 316 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 317 |
$settings = $_POST['order_bump_data']; |
| 318 |
} else { |
| 319 |
$settings = $this->ob_settings; |
| 320 |
} |
| 321 |
|
| 322 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 323 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 324 |
|
| 325 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 326 |
|
| 327 |
if( $settings['isEnabled'] && $settings['position'] == 'before-checkout'){ |
| 328 |
if( $settings['isEnabled'] === 'no' ){ |
| 329 |
continue; |
| 330 |
} |
| 331 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 332 |
if ( !empty($settings['selectedStyle']) ) { |
| 333 |
ob_start(); |
| 334 |
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'; |
| 341 |
} |
| 342 |
} 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>'; |
| 344 |
} |
| 345 |
} else { |
| 346 |
$order_bump_settings = $settings; |
| 347 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 348 |
} |
| 349 |
$output .= ob_get_clean(); |
| 350 |
} |
| 351 |
} |
| 352 |
else { |
| 353 |
wc_clear_notices(); |
| 354 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
} |
| 360 |
|
| 361 |
echo $output; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
/** |
| 366 |
* Render order bump markup |
| 367 |
* |
| 368 |
* @since 2.0.3 |
| 369 |
*/ |
| 370 |
public function render_order_bump_before_lms_order_deatils() { |
| 371 |
|
| 372 |
global $post; |
| 373 |
$checkout_id = 0; |
| 374 |
$output = ''; |
| 375 |
if ( $post ) { |
| 376 |
$checkout_id = $post->ID; |
| 377 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 378 |
$checkout_id = intval( $_POST['post_id'] ); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 383 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 384 |
$settings = $_POST['order_bump_data']; |
| 385 |
} else { |
| 386 |
$settings = $this->ob_settings; |
| 387 |
} |
| 388 |
$funnel_id = get_post_meta($checkout_id,'_funnel_id',true); |
| 389 |
$type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true); |
| 390 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 391 |
|
| 392 |
if( $settings['isEnabled'] && $settings['position'] == 'before-lms-order'){ |
| 393 |
if( $settings['isEnabled'] === 'no' ){ |
| 394 |
continue; |
| 395 |
} |
| 396 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 397 |
if ( !empty($settings['selectedStyle']) ) { |
| 398 |
ob_start(); |
| 399 |
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'; |
| 406 |
} |
| 407 |
} 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>'; |
| 409 |
} |
| 410 |
} else { |
| 411 |
$order_bump_settings = $settings; |
| 412 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 413 |
} |
| 414 |
$output .= ob_get_clean(); |
| 415 |
} |
| 416 |
} |
| 417 |
else { |
| 418 |
wc_clear_notices(); |
| 419 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 420 |
} |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
} |
| 425 |
|
| 426 |
echo $output; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
/** |
| 431 |
* Render order bump markup |
| 432 |
* |
| 433 |
* @since 2.0.3 |
| 434 |
*/ |
| 435 |
public function render_order_bump_after_lms_order_deatils() { |
| 436 |
|
| 437 |
global $post; |
| 438 |
$checkout_id = 0; |
| 439 |
$output = ''; |
| 440 |
if ( $post ) { |
| 441 |
$checkout_id = $post->ID; |
| 442 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 443 |
$checkout_id = intval( $_POST['post_id'] ); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 448 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 449 |
$settings = $_POST['order_bump_data']; |
| 450 |
} else { |
| 451 |
$settings = $this->ob_settings; |
| 452 |
} |
| 453 |
|
| 454 |
$funnel_id = get_post_meta($checkout_id,'_funnel_id',true); |
| 455 |
$type = get_post_meta($funnel_id,'_wpfnl_funnel_type',true); |
| 456 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 457 |
|
| 458 |
if( $settings['isEnabled'] && $settings['position'] == 'after-lms-order'){ |
| 459 |
if( $settings['isEnabled'] === 'no' ){ |
| 460 |
continue; |
| 461 |
} |
| 462 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 463 |
if ( !empty($settings['selectedStyle']) ) { |
| 464 |
ob_start(); |
| 465 |
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'; |
| 472 |
} |
| 473 |
} 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>'; |
| 475 |
} |
| 476 |
} else { |
| 477 |
$order_bump_settings = $settings; |
| 478 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 479 |
} |
| 480 |
$output .= ob_get_clean(); |
| 481 |
} |
| 482 |
} |
| 483 |
else { |
| 484 |
wc_clear_notices(); |
| 485 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
} |
| 491 |
|
| 492 |
echo $output; |
| 493 |
} |
| 494 |
|
| 495 |
/** |
| 496 |
* Render order bump markup |
| 497 |
* |
| 498 |
* @since 2.0.3 |
| 499 |
*/ |
| 500 |
public function render_order_bump_before_payment() { |
| 501 |
|
| 502 |
|
| 503 |
global $post; |
| 504 |
$checkout_id = 0; |
| 505 |
$output = ''; |
| 506 |
if ( $post ) { |
| 507 |
$checkout_id = $post->ID; |
| 508 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 509 |
$checkout_id = intval( $_POST['post_id'] ); |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 514 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 515 |
$settings = $_POST['order_bump_data']; |
| 516 |
} else { |
| 517 |
$settings = $this->ob_settings; |
| 518 |
} |
| 519 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 520 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 521 |
|
| 522 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 523 |
|
| 524 |
if( $settings['isEnabled'] && $settings['position'] == 'before-payment'){ |
| 525 |
if( $settings['isEnabled'] === 'no' ){ |
| 526 |
continue; |
| 527 |
} |
| 528 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 529 |
if ( !empty($settings['selectedStyle']) ) { |
| 530 |
ob_start(); |
| 531 |
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'; |
| 538 |
} |
| 539 |
} 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>'; |
| 541 |
} |
| 542 |
} else { |
| 543 |
$order_bump_settings = $settings; |
| 544 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 545 |
} |
| 546 |
$output .= ob_get_clean(); |
| 547 |
} |
| 548 |
} |
| 549 |
else { |
| 550 |
wc_clear_notices(); |
| 551 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
} |
| 557 |
|
| 558 |
echo $output; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
/** |
| 563 |
* Render order bump markup |
| 564 |
* |
| 565 |
* @since 2.0.3 |
| 566 |
*/ |
| 567 |
public function render_order_bump_after_payment() { |
| 568 |
|
| 569 |
global $post; |
| 570 |
$checkout_id = 0; |
| 571 |
$output = ''; |
| 572 |
|
| 573 |
if ( $post ) { |
| 574 |
$checkout_id = $post->ID; |
| 575 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 576 |
$checkout_id = intval( $_POST['post_id'] ); |
| 577 |
} |
| 578 |
|
| 579 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 580 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 581 |
$settings = $_POST['order_bump_data']; |
| 582 |
} else { |
| 583 |
$settings = $this->ob_settings; |
| 584 |
} |
| 585 |
|
| 586 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 587 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 588 |
|
| 589 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 590 |
|
| 591 |
if( $settings['isEnabled'] && $settings['position'] == 'after-payment'){ |
| 592 |
if( $settings['isEnabled'] === 'no' ){ |
| 593 |
continue; |
| 594 |
} |
| 595 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 596 |
if ( !empty($settings['selectedStyle']) ) { |
| 597 |
ob_start(); |
| 598 |
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'; |
| 605 |
} |
| 606 |
} 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>'; |
| 608 |
} |
| 609 |
} else { |
| 610 |
$order_bump_settings = $settings; |
| 611 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 612 |
} |
| 613 |
$output .= ob_get_clean(); |
| 614 |
} |
| 615 |
} |
| 616 |
else { |
| 617 |
wc_clear_notices(); |
| 618 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
} |
| 624 |
|
| 625 |
echo $output; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
/** |
| 630 |
* Render order bump markup |
| 631 |
* |
| 632 |
* @since 2.0.3 |
| 633 |
*/ |
| 634 |
public function render_order_bump_after_customer_details() { |
| 635 |
|
| 636 |
global $post; |
| 637 |
$checkout_id = 0; |
| 638 |
$output = ''; |
| 639 |
if ( $post ) { |
| 640 |
$checkout_id = $post->ID; |
| 641 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 642 |
$checkout_id = intval( $_POST['post_id'] ); |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 648 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 649 |
$settings = $_POST['order_bump_data']; |
| 650 |
} else { |
| 651 |
$settings = $this->ob_settings; |
| 652 |
} |
| 653 |
|
| 654 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 655 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 656 |
|
| 657 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 658 |
if( $settings['isEnabled'] && $settings['position'] == 'after-customer-details'){ |
| 659 |
if( $settings['isEnabled'] === 'no' ){ |
| 660 |
continue; |
| 661 |
} |
| 662 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 663 |
if ( !empty($settings['selectedStyle']) ) { |
| 664 |
ob_start(); |
| 665 |
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'; |
| 672 |
} |
| 673 |
} 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>'; |
| 675 |
} |
| 676 |
} else { |
| 677 |
$order_bump_settings = $settings; |
| 678 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 679 |
} |
| 680 |
$output .= ob_get_clean(); |
| 681 |
} |
| 682 |
} |
| 683 |
else { |
| 684 |
wc_clear_notices(); |
| 685 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
} |
| 691 |
|
| 692 |
echo $output; |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
/** |
| 697 |
* Render order bump markup |
| 698 |
* |
| 699 |
* @since 2.0.3 |
| 700 |
*/ |
| 701 |
public function render_order_bump_after_order() { |
| 702 |
|
| 703 |
global $post; |
| 704 |
$checkout_id = 0; |
| 705 |
$output = ''; |
| 706 |
|
| 707 |
if ( $post ) { |
| 708 |
$checkout_id = $post->ID; |
| 709 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 710 |
$checkout_id = intval( $_POST['post_id'] ); |
| 711 |
} |
| 712 |
|
| 713 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 714 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 715 |
$settings = $_POST['order_bump_data']; |
| 716 |
} else { |
| 717 |
$settings = $this->ob_settings; |
| 718 |
} |
| 719 |
|
| 720 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 721 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 722 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 723 |
|
| 724 |
if( $settings['isEnabled'] && $settings['position'] == 'after-order'){ |
| 725 |
|
| 726 |
|
| 727 |
if( $settings['isEnabled'] === 'no' ){ |
| 728 |
continue; |
| 729 |
} |
| 730 |
|
| 731 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 732 |
if ( !empty($settings['selectedStyle']) ) { |
| 733 |
ob_start(); |
| 734 |
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'; |
| 741 |
} |
| 742 |
} 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>'; |
| 744 |
} |
| 745 |
} else { |
| 746 |
$order_bump_settings = $settings; |
| 747 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 748 |
} |
| 749 |
$output .= ob_get_clean(); |
| 750 |
} |
| 751 |
} |
| 752 |
else { |
| 753 |
wc_clear_notices(); |
| 754 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 755 |
} |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
} |
| 760 |
|
| 761 |
echo $output; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
/** |
| 766 |
* Render order bump markup |
| 767 |
* |
| 768 |
* @since 2.0.3 |
| 769 |
*/ |
| 770 |
public function render_order_bump_before_order() { |
| 771 |
|
| 772 |
global $post; |
| 773 |
$checkout_id = 0; |
| 774 |
$output = ''; |
| 775 |
|
| 776 |
|
| 777 |
if ( $post ) { |
| 778 |
$checkout_id = $post->ID; |
| 779 |
} elseif ( is_admin() && isset( $_POST['post_id'] ) ) { |
| 780 |
$checkout_id = intval( $_POST['post_id'] ); |
| 781 |
} |
| 782 |
|
| 783 |
if( Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' ) ) { |
| 784 |
if ( ! empty( $_POST['order_bump_data'] ) ) { |
| 785 |
$settings = $_POST['order_bump_data']; |
| 786 |
} else { |
| 787 |
$settings = $this->ob_settings; |
| 788 |
} |
| 789 |
|
| 790 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 791 |
$type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ); |
| 792 |
|
| 793 |
foreach( $this->ob_settings as $key=> $settings ){ |
| 794 |
|
| 795 |
if( $settings['isEnabled'] && $settings['position'] == 'before-order'){ |
| 796 |
if( $settings['isEnabled'] === 'no' ){ |
| 797 |
continue; |
| 798 |
} |
| 799 |
|
| 800 |
if (isset($settings['product']) && $settings['product'] != '') { |
| 801 |
if ( !empty($settings['selectedStyle']) ) { |
| 802 |
ob_start(); |
| 803 |
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'; |
| 810 |
} |
| 811 |
} 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>'; |
| 813 |
} |
| 814 |
} else { |
| 815 |
$order_bump_settings = $settings; |
| 816 |
require WPFNL_DIR . 'public/modules/checkout/templates-style/order-bump-template-' . $settings['selectedStyle'] . '.php'; |
| 817 |
} |
| 818 |
$output .= ob_get_clean(); |
| 819 |
} |
| 820 |
} |
| 821 |
else { |
| 822 |
wc_clear_notices(); |
| 823 |
wc_add_notice(__('No product is added to this order bump. Please select one.', 'wpfnl'), 'error'); |
| 824 |
} |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
} |
| 829 |
|
| 830 |
echo $output; |
| 831 |
} |
| 832 |
} |