| 1 |
<?php |
| 2 |
/** |
| 3 |
* Order details shortcode class |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Shortcodes; |
| 8 |
|
| 9 |
use WPFunnels\Meta\Wpfnl_Default_Meta; |
| 10 |
use WPFunnels\Wpfnl_functions; |
| 11 |
use WPFunnels\Wpfnl; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class WC_Shortcode_Optin |
| 15 |
* |
| 16 |
* @package WPFunnels\Shortcodes |
| 17 |
*/ |
| 18 |
class Wpfnl_Shortcode_Checkout { |
| 19 |
|
| 20 |
/** |
| 21 |
* Attributes |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
protected $attributes = array(); |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* Wpfnl_Shortcode_Order_details constructor. |
| 30 |
* |
| 31 |
* @param array $attributes |
| 32 |
*/ |
| 33 |
public function __construct( $attributes = array() ) { |
| 34 |
|
| 35 |
$this->attributes = $this->parse_attributes( $attributes ); |
| 36 |
|
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
/** |
| 42 |
* Get shortcode attributes. |
| 43 |
* |
| 44 |
* @since 3.2.0 |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function get_attributes() { |
| 48 |
return $this->attributes; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
/** |
| 53 |
* Parse attributes |
| 54 |
* |
| 55 |
* @param $attributes |
| 56 |
* |
| 57 |
* @return array |
| 58 |
*/ |
| 59 |
protected function parse_attributes( $attributes ) { |
| 60 |
|
| 61 |
$attributes = shortcode_atts( |
| 62 |
array( |
| 63 |
'type' => 'two-column', |
| 64 |
'order_bump' => 'yes', |
| 65 |
'class' => '' |
| 66 |
), |
| 67 |
$attributes |
| 68 |
); |
| 69 |
return $attributes; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Get wrapper classes |
| 74 |
* |
| 75 |
* @return array |
| 76 |
*/ |
| 77 |
protected function get_wrapper_classes() { |
| 78 |
$classes = array( 'wpfnl', 'wpfnl-order-details-wrapper' ); |
| 79 |
return $classes; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
/** |
| 84 |
* Content of optin form |
| 85 |
* |
| 86 |
* @return string |
| 87 |
*/ |
| 88 |
public function get_content() { |
| 89 |
|
| 90 |
if( Wpfnl_functions::check_if_this_is_step_type('checkout') ) { |
| 91 |
|
| 92 |
//===Coupon Enabler===// |
| 93 |
$coupon_enabler = get_post_meta(get_the_ID(), '_wpfnl_checkout_coupon', true); |
| 94 |
if ( 'no' === $coupon_enabler ) { |
| 95 |
remove_action('woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10); |
| 96 |
} |
| 97 |
|
| 98 |
$checkout_layout = ''; |
| 99 |
$session_value = ''; |
| 100 |
if( esc_html($this->attributes['type']) == 'one-column' ){ |
| 101 |
$checkout_layout = 'wpfnl-col-1'; |
| 102 |
$session_value = 'wpfnl-col-1'; |
| 103 |
}elseif( esc_html($this->attributes['type']) == 'two-column' ){ |
| 104 |
$checkout_layout = 'wpfnl-col-2'; |
| 105 |
$session_value = 'wpfnl-col-2'; |
| 106 |
}else{ |
| 107 |
if( Wpfnl_functions::is_wpfnl_pro_activated() && 'multistep' === esc_html($this->attributes['type']) ){ |
| 108 |
$checkout_layout = 'wpfnl-multistep'; |
| 109 |
$session_value = 'wpfnl-multistep'; |
| 110 |
}if( Wpfnl_functions::is_wpfnl_pro_activated() && 'wpfnl-two-step' === esc_html($this->attributes['type']) ){ |
| 111 |
$checkout_layout = 'wpfnl-2-step wpfnl-multistep '; |
| 112 |
$session_value = 'wpfnl-2-step'; |
| 113 |
}elseif( !Wpfnl_functions::is_wpfnl_pro_activated() && 'multistep' === esc_html($this->attributes['type']) ) { |
| 114 |
$checkout_layout = 'wpfnl-col-2'; |
| 115 |
$session_value = 'wpfnl-col-2'; |
| 116 |
}elseif( Wpfnl_functions::is_wpfnl_pro_activated() && 'wpfnl-express-checkout' === esc_html($this->attributes['type']) ) { |
| 117 |
$checkout_layout = 'wpfnl-express-checkout'; |
| 118 |
$session_value = 'wpfnl-express-checkout'; |
| 119 |
} |
| 120 |
} |
| 121 |
if( PHP_SESSION_DISABLED == session_status() ) { |
| 122 |
session_start(); |
| 123 |
} |
| 124 |
$_SESSION[ 'checkout_layout' ] = $session_value; |
| 125 |
if( Wpfnl_functions::is_wpfnl_pro_activated() && 'wpfnl-express-checkout' === $checkout_layout ) { |
| 126 |
$checkout_layout .= ' wpfnl-multistep'; |
| 127 |
} |
| 128 |
|
| 129 |
query_posts('post_type="checkout"'); |
| 130 |
if(sanitize_text_field($this->attributes['order_bump']) == 'yes'){ |
| 131 |
do_action( 'wpfunnels/before_checkout_form', get_the_ID() ); |
| 132 |
} |
| 133 |
$class = ''; |
| 134 |
if (isset($this->attributes['class']) && NUll != (esc_html($this->attributes['class']))){ |
| 135 |
$class = esc_html($this->attributes['class']); |
| 136 |
} |
| 137 |
|
| 138 |
$html = ''; |
| 139 |
$html .= '<div class="wpfnl-checkout '.$checkout_layout.' '.$class.'">'; |
| 140 |
$html .= do_shortcode('[woocommerce_checkout]'); |
| 141 |
$html .= '</div>'; |
| 142 |
|
| 143 |
return $html; |
| 144 |
} |
| 145 |
return false; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
/** |
| 150 |
* Render order bump |
| 151 |
*/ |
| 152 |
public function render_order_bump(){ |
| 153 |
add_action( 'wpfunnels/before_checkout_form', array( $this, 'load_actions' ), 10, 2 ); |
| 154 |
} |
| 155 |
|
| 156 |
public function load_actions( $checkout_id, $settings = array() ) { |
| 157 |
|
| 158 |
$checkout_meta = new Wpfnl_Default_Meta(); |
| 159 |
// $is_order_bump_enabled = $checkout_meta->get_checkout_meta_value($checkout_id, 'order-bump'); |
| 160 |
$funnel_id = get_post_meta( $checkout_id, '_funnel_id', true ); |
| 161 |
// if ( 'yes' !== $is_order_bump_enabled ) { |
| 162 |
// return; |
| 163 |
// } |
| 164 |
|
| 165 |
|
| 166 |
$this->ob_settings = $checkout_meta->get_checkout_meta_value($checkout_id, 'order-bump-settings', wpfnl()->meta->get_default_order_bump_meta()); |
| 167 |
$this->ob_settings = apply_filters( 'wpfunnels/order_bump_settings', $this->ob_settings, $funnel_id, $checkout_id ); |
| 168 |
$this->trigger_ob_actions(); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
/** |
| 173 |
* Trigger WC action for order bump |
| 174 |
*/ |
| 175 |
private function trigger_ob_actions() { |
| 176 |
|
| 177 |
foreach( $this->ob_settings as $key=>$settings ){ |
| 178 |
$position = $this->get_order_bump_attribute( $settings, 'position' ); |
| 179 |
|
| 180 |
if( !$position ) { |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
switch ($position) { |
| 185 |
case 'before-checkout': |
| 186 |
add_action('woocommerce_before_checkout_form', [$this, 'render_order_bump'], 10); |
| 187 |
break; |
| 188 |
case 'after-order': |
| 189 |
add_action('woocommerce_checkout_order_review', [$this, 'render_order_bump'], 8); |
| 190 |
break; |
| 191 |
case 'after-customer-details': |
| 192 |
add_action('woocommerce_after_order_notes', [$this, 'render_order_bump'], 8); |
| 193 |
break; |
| 194 |
case 'before-payment': |
| 195 |
add_action('woocommerce_review_order_before_payment', [$this, 'render_order_bump'], 8); |
| 196 |
break; |
| 197 |
case 'after-payment': |
| 198 |
add_action('woocommerce_review_order_after_payment', [$this, 'render_order_bump'], 8); |
| 199 |
break; |
| 200 |
case 'popup': |
| 201 |
$settings['selectedStyle'] = 'popup'; |
| 202 |
$this->render_popup_in_elementor_editor(); |
| 203 |
break; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
/** |
| 211 |
* Get order bump attribute from order bump settings data |
| 212 |
* |
| 213 |
* @param $order_bump_data |
| 214 |
* @param $key |
| 215 |
* |
| 216 |
* @return bool|mixed |
| 217 |
*/ |
| 218 |
private function get_order_bump_attribute( $order_bump_data, $key ) { |
| 219 |
if( !isset($order_bump_data[$key]) ) { |
| 220 |
return false; |
| 221 |
} |
| 222 |
return $order_bump_data[$key]; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
/** |
| 227 |
* Render popup style for order bump in elementor |
| 228 |
* builder preview |
| 229 |
* |
| 230 |
* @since 2.0.3 |
| 231 |
*/ |
| 232 |
public function render_popup_in_elementor_editor() { |
| 233 |
if(Wpfnl_functions::is_elementor_active()) { |
| 234 |
if (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_admin()) { |
| 235 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 236 |
} else { |
| 237 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 238 |
} |
| 239 |
} else { |
| 240 |
add_action( 'woocommerce_before_checkout_form', [ $this, 'render_order_bump' ], 10 ); |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
} |
| 245 |
|