PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / shortcodes / class-wpfnl-shortcode-checkout.php

class-wpfnl-shortcode-checkout.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at includes/core/shortcodes/class-wpfnl-shortcode-checkout.php

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