PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
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 2.8.17 2.8.18 All 259 releases
wpfunnels / includes / core / widgets / bricks / OrderDetailsWidget.php

OrderDetailsWidget.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at includes/core/widgets/bricks/OrderDetailsWidget.php

536 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Namespace for the OrderDetailsWidget class.
5 *
6 * This namespace defines the location of the OrderDetailsWidget class within the WPFunnels\Widgets\Bricks namespace.
7 */
8 namespace WPFunnels\Widgets\Bricks;
9
10 require_once get_template_directory() . '/includes/elements/base.php';
11
12 use \Bricks\Element;
13 use Error;
14
15 if (! defined('ABSPATH')) {
16 exit;
17 } // Exit if accessed directly
18
19
20 /**
21 * Class OrderDetailsWidget
22 *
23 * Represents a widget for displaying order details.
24 *
25 * @package WPFunnels\Widgets\Bricks
26 */
27 class OrderDetailsWidget extends Element
28 {
29
30 // Element properties
31 public $category = 'wpfunnels'; // Use predefined element category 'general'
32 public $name = 'wpfnl_order_deatils'; // Make sure to prefix your elements
33 public $icon = 'fa-solid fa-cart-shopping'; // Themify icon font class
34 public $css_selector = '.wpfunnels-bricks-order-details-icon'; // Default CSS selector
35 public $scripts = []; // Script(s) run when element is rendered on frontend or updated in builder
36
37
38 /**
39 * Return localised element label
40 *
41 * @return string
42 * @since 3.1.0
43 */
44 public function get_label()
45 {
46 return esc_html__('Order Detail', 'wpfnl');
47 }
48
49 /**
50 * Get WordPress user roles for display condition control.
51 *
52 * @return array
53 * @since 3.1.0
54 */
55 protected function get_wp_user_roles()
56 {
57 $roles = [ 'none' => esc_html__( 'None', 'wpfnl' ) ];
58
59 if ( ! function_exists( 'get_editable_roles' ) ) {
60 require_once ABSPATH . 'wp-admin/includes/user.php';
61 }
62
63 foreach ( get_editable_roles() as $role_key => $role_info ) {
64 $roles[ $role_key ] = $role_info['name'];
65 }
66
67 return $roles;
68 }
69
70
71 /**
72 * Set builder control groups
73 *
74 * @since 3.1.0
75 */
76 public function set_control_groups()
77 {
78 $this->control_groups['wpfunnels'] = [
79 'title' => esc_html__('Settings', 'wpfnl'), // Localized control group title
80 'tab' => 'content', // Set to either "content" or "style"
81 ];
82 }
83
84 /**
85 * Set builder controls
86 *
87 * @since 3.1.0
88 */
89 public function set_controls()
90 {
91
92 $wpfnl_thankyou_order_overview = get_post_meta($this->post_id, '_wpfnl_thankyou_order_overview', true);
93 $wpfnl_thankyou_order_details = get_post_meta($this->post_id, '_wpfnl_thankyou_order_details', true);
94 $wpfnl_thankyou_billing_details = get_post_meta($this->post_id, '_wpfnl_thankyou_billing_details', true);
95 $wpfnl_thankyou_shipping_details = get_post_meta($this->post_id, '_wpfnl_thankyou_shipping_details', true);
96
97 if (!$wpfnl_thankyou_order_overview) {
98 $wpfnl_thankyou_order_overview = 'on';
99 }
100 if (!$wpfnl_thankyou_order_details) {
101 $wpfnl_thankyou_order_details = 'on';
102 }
103 if (!$wpfnl_thankyou_billing_details) {
104 $wpfnl_thankyou_billing_details = 'on';
105 }
106 if (!$wpfnl_thankyou_shipping_details) {
107 $wpfnl_thankyou_shipping_details = 'on';
108 }
109
110
111 $this->controls['enable_order_review'] = [
112 'tab' => 'content',
113 'group' => 'wpfunnels',
114 'label' => esc_html__('Show Order Overview', 'wpfnl'),
115 'type' => 'select',
116 'options' => [
117 'on' => esc_html__( 'On', 'wpfnl' ),
118 'off' => esc_html__( 'Off', 'wpfnl' ),
119 ],
120 'inline' => true,
121 'clearable' => false,
122 'pasteStyles' => false,
123 'default' => $wpfnl_thankyou_order_overview,
124 ];
125
126 $this->controls['enable_order_details'] = [
127 'tab' => 'content',
128 'group' => 'wpfunnels',
129 'label' => esc_html__('Show Order Details', 'wpfnl'),
130 'type' => 'select',
131 'options' => [
132 'on' => esc_html__( 'On', 'wpfnl' ),
133 'off' => esc_html__( 'Off', 'wpfnl' ),
134 ],
135 'inline' => true,
136 'clearable' => false,
137 'pasteStyles' => false,
138 'default' => $wpfnl_thankyou_order_details,
139 ];
140
141 $this->controls['enable_billing_details'] = [
142 'tab' => 'content',
143 'group' => 'wpfunnels',
144 'label' => esc_html__('Show Billing Details', 'wpfnl'),
145 'type' => 'select',
146 'options' => [
147 'on' => esc_html__( 'On', 'wpfnl' ),
148 'off' => esc_html__( 'Off', 'wpfnl' ),
149 ],
150 'inline' => true,
151 'clearable' => false,
152 'pasteStyles' => false,
153 'default' => $wpfnl_thankyou_billing_details,
154 ];
155
156 $this->controls['enable_shipping_details'] = [
157 'tab' => 'content',
158 'group' => 'wpfunnels',
159 'label' => esc_html__('Show Shipping Details', 'wpfnl'),
160 'type' => 'select',
161 'options' => [
162 'on' => esc_html__( 'On', 'wpfnl' ),
163 'off' => esc_html__( 'Off', 'wpfnl' ),
164 ],
165 'inline' => true,
166 'clearable' => false,
167 'pasteStyles' => false,
168 'default' => $wpfnl_thankyou_shipping_details,
169 ];
170
171 // Responsive Display
172 $this->controls['responsiveSeparator'] = [
173 'tab' => 'content',
174 'group' => 'wpfunnels',
175 'label' => esc_html__( 'Responsive Display', 'wpfnl' ),
176 'type' => 'separator',
177 ];
178
179 $this->controls['hide_on_desktop'] = [
180 'tab' => 'content',
181 'group' => 'wpfunnels',
182 'label' => esc_html__( 'Hide on Desktop (≥ 1200px)', 'wpfnl' ),
183 'type' => 'checkbox',
184 'default' => false,
185 'description' => esc_html__( 'Hide order details on desktop devices (window width >= 1200px)', 'wpfnl' ),
186 ];
187
188 $this->controls['hide_on_tablet'] = [
189 'tab' => 'content',
190 'group' => 'wpfunnels',
191 'label' => esc_html__( 'Hide on Tablet (768px – 1199px)', 'wpfnl' ),
192 'type' => 'checkbox',
193 'default' => false,
194 'description' => esc_html__( 'Hide order details on tablet devices (window width 768px - 1199px)', 'wpfnl' ),
195 ];
196
197 $this->controls['hide_on_mobile'] = [
198 'tab' => 'content',
199 'group' => 'wpfunnels',
200 'label' => esc_html__( 'Hide on Mobile (≤ 767px)', 'wpfnl' ),
201 'type' => 'checkbox',
202 'default' => false,
203 'description' => esc_html__( 'Hide order details on mobile devices (window width <= 767px)', 'wpfnl' ),
204 ];
205
206 // Display Conditions
207 $this->controls['displayConditionSeparator'] = [
208 'tab' => 'content',
209 'group' => 'wpfunnels',
210 'label' => esc_html__( 'Display Conditions', 'wpfnl' ),
211 'type' => 'separator',
212 ];
213
214 $this->controls['display_condition_type'] = [
215 'tab' => 'content',
216 'group' => 'wpfunnels',
217 'label' => esc_html__( 'Display Condition', 'wpfnl' ),
218 'type' => 'select',
219 'options' => [
220 'none' => esc_html__( 'None', 'wpfnl' ),
221 'user_state' => esc_html__( 'User State', 'wpfnl' ),
222 'user_role' => esc_html__( 'User Role', 'wpfnl' ),
223 'browser' => esc_html__( 'Browser', 'wpfnl' ),
224 'operating_system' => esc_html__( 'Operating System', 'wpfnl' ),
225 'day' => esc_html__( 'Day', 'wpfnl' ),
226 ],
227 'inline' => false,
228 'default' => 'none',
229 ];
230
231 // User State
232 $this->controls['hide_from_logged_in'] = [
233 'tab' => 'content',
234 'group' => 'wpfunnels',
235 'label' => esc_html__( 'Hide From Logged In User', 'wpfnl' ),
236 'type' => 'checkbox',
237 'default' => false,
238 'required' => [ 'display_condition_type', '=', 'user_state' ],
239 ];
240
241 $this->controls['hide_from_logged_out'] = [
242 'tab' => 'content',
243 'group' => 'wpfunnels',
244 'label' => esc_html__( 'Hide From Logged Out User', 'wpfnl' ),
245 'type' => 'checkbox',
246 'default' => false,
247 'required' => [ 'display_condition_type', '=', 'user_state' ],
248 ];
249
250 // User Role
251 $this->controls['hide_for_user_role'] = [
252 'tab' => 'content',
253 'group' => 'wpfunnels',
254 'label' => esc_html__( 'Hide For User Role', 'wpfnl' ),
255 'type' => 'select',
256 'options' => $this->get_wp_user_roles(),
257 'default' => 'none',
258 'required' => [ 'display_condition_type', '=', 'user_role' ],
259 ];
260
261 // Browser
262 $this->controls['hide_on_browser'] = [
263 'tab' => 'content',
264 'group' => 'wpfunnels',
265 'label' => esc_html__( 'Hide On Browser', 'wpfnl' ),
266 'type' => 'select',
267 'options' => [
268 'none' => esc_html__( 'None', 'wpfnl' ),
269 'mozilla' => esc_html__( 'Mozilla Firefox', 'wpfnl' ),
270 'chrome' => esc_html__( 'Google Chrome', 'wpfnl' ),
271 'opera_mini' => esc_html__( 'Opera Mini', 'wpfnl' ),
272 'safari' => esc_html__( 'Safari', 'wpfnl' ),
273 'edge' => esc_html__( 'Microsoft Edge', 'wpfnl' ),
274 ],
275 'default' => 'none',
276 'required' => [ 'display_condition_type', '=', 'browser' ],
277 ];
278
279 // Operating System
280 $this->controls['hide_on_os'] = [
281 'tab' => 'content',
282 'group' => 'wpfunnels',
283 'label' => esc_html__( 'Hide On Operating System', 'wpfnl' ),
284 'type' => 'select',
285 'options' => [
286 'none' => esc_html__( 'None', 'wpfnl' ),
287 'ios' => esc_html__( 'iOS', 'wpfnl' ),
288 'android' => esc_html__( 'Android', 'wpfnl' ),
289 'windows' => esc_html__( 'Windows', 'wpfnl' ),
290 'macos' => esc_html__( 'MacOS', 'wpfnl' ),
291 'linux' => esc_html__( 'Linux', 'wpfnl' ),
292 'sunos' => esc_html__( 'SunOS', 'wpfnl' ),
293 'openbsd' => esc_html__( 'OpenBSD', 'wpfnl' ),
294 ],
295 'default' => 'none',
296 'required' => [ 'display_condition_type', '=', 'operating_system' ],
297 ];
298
299 // Day
300 $this->controls['disable_on_days'] = [
301 'tab' => 'content',
302 'group' => 'wpfunnels',
303 'label' => esc_html__( 'Select Days You Want To Disable', 'wpfnl' ),
304 'type' => 'select',
305 'multiple' => true,
306 'options' => [
307 'monday' => esc_html__( 'Monday', 'wpfnl' ),
308 'tuesday' => esc_html__( 'Tuesday', 'wpfnl' ),
309 'wednesday' => esc_html__( 'Wednesday', 'wpfnl' ),
310 'thursday' => esc_html__( 'Thursday', 'wpfnl' ),
311 'friday' => esc_html__( 'Friday', 'wpfnl' ),
312 'saturday' => esc_html__( 'Saturday', 'wpfnl' ),
313 'sunday' => esc_html__( 'Sunday', 'wpfnl' ),
314 ],
315 'default' => [],
316 'required' => [ 'display_condition_type', '=', 'day' ],
317 ];
318
319 // Animation
320 $this->controls['animationSeparator'] = [
321 'tab' => 'content',
322 'group' => 'wpfunnels',
323 'label' => esc_html__( 'Animation', 'wpfnl' ),
324 'type' => 'separator',
325 ];
326
327 $this->controls['entrance_animation'] = [
328 'tab' => 'content',
329 'group' => 'wpfunnels',
330 'label' => esc_html__( 'Entrance Animation', 'wpfnl' ),
331 'type' => 'select',
332 'options' => [
333 '' => esc_html__( 'None', 'wpfnl' ),
334 'fadeIn' => esc_html__( 'Fade In', 'wpfnl' ),
335 'fadeInUp' => esc_html__( 'Fade In Up', 'wpfnl' ),
336 'fadeInDown' => esc_html__( 'Fade In Down', 'wpfnl' ),
337 'fadeInLeft' => esc_html__( 'Fade In Left', 'wpfnl' ),
338 'fadeInRight'=> esc_html__( 'Fade In Right', 'wpfnl' ),
339 'zoomIn' => esc_html__( 'Zoom In', 'wpfnl' ),
340 'zoomInUp' => esc_html__( 'Zoom In Up', 'wpfnl' ),
341 'bounceIn' => esc_html__( 'Bounce In', 'wpfnl' ),
342 'bounceInUp' => esc_html__( 'Bounce In Up', 'wpfnl' ),
343 'slideInUp' => esc_html__( 'Slide In Up', 'wpfnl' ),
344 'slideInLeft'=> esc_html__( 'Slide In Left', 'wpfnl' ),
345 'slideInRight'=> esc_html__( 'Slide In Right', 'wpfnl' ),
346 'flipInX' => esc_html__( 'Flip In X', 'wpfnl' ),
347 'flipInY' => esc_html__( 'Flip In Y', 'wpfnl' ),
348 'pulse' => esc_html__( 'Pulse', 'wpfnl' ),
349 'tada' => esc_html__( 'Tada', 'wpfnl' ),
350 'wobble' => esc_html__( 'Wobble', 'wpfnl' ),
351 ],
352 'inline' => false,
353 'placeholder' => esc_html__( 'None', 'wpfnl' ),
354 'default' => '',
355 'description' => esc_html__( 'Animation plays when the order details enters the viewport on the live page.', 'wpfnl' ),
356 ];
357 }
358
359
360 /**
361 * Render the widget output on the frontend.
362 *
363 * Written in PHP and used to generate the final HTML.
364 *
365 * @since 3.1.0
366 *
367 * @access public
368 */
369 public function render()
370 {
371 $settings = $this->settings;
372
373 // ---- Display Conditions ----------------------------------------
374 $display_condition = ! empty( $settings['display_condition_type'] ) ? $settings['display_condition_type'] : 'none';
375
376 if ( $display_condition === 'user_state' ) {
377 $hide_logged_in = ! empty( $settings['hide_from_logged_in'] );
378 $hide_logged_out = ! empty( $settings['hide_from_logged_out'] );
379
380 if ( $hide_logged_in && is_user_logged_in() ) {
381 return;
382 }
383 if ( $hide_logged_out && ! is_user_logged_in() ) {
384 return;
385 }
386
387 } elseif ( $display_condition === 'user_role' ) {
388 $hide_for_user_role = ! empty( $settings['hide_for_user_role'] ) ? $settings['hide_for_user_role'] : 'none';
389
390 if ( $hide_for_user_role !== 'none' && is_user_logged_in() ) {
391 $user = wp_get_current_user();
392 if ( in_array( $hide_for_user_role, $user->roles ) ) {
393 return;
394 }
395 }
396
397 } elseif ( $display_condition === 'day' ) {
398 $disable_on_days = ! empty( $settings['disable_on_days'] ) ? $settings['disable_on_days'] : [];
399
400 if ( ! empty( $disable_on_days ) && is_array( $disable_on_days ) ) {
401 $current_day = strtolower( date( 'l' ) ); // e.g., 'monday'
402 if ( in_array( $current_day, $disable_on_days ) ) {
403 return;
404 }
405 }
406
407 } elseif ( $display_condition === 'browser' ) {
408 $hide_on_browser = ! empty( $settings['hide_on_browser'] ) ? $settings['hide_on_browser'] : 'none';
409
410 if ( $hide_on_browser !== 'none' ) {
411 $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
412 $current_browser = '';
413
414 if ( strpos( $user_agent, 'edg' ) !== false ) {
415 $current_browser = 'edge';
416 } elseif ( strpos( $user_agent, 'opr' ) !== false || strpos( $user_agent, 'opera' ) !== false ) {
417 $current_browser = 'opera_mini';
418 } elseif ( strpos( $user_agent, 'chrome' ) !== false ) {
419 $current_browser = 'chrome';
420 } elseif ( strpos( $user_agent, 'safari' ) !== false ) {
421 $current_browser = 'safari';
422 } elseif ( strpos( $user_agent, 'firefox' ) !== false ) {
423 $current_browser = 'mozilla';
424 }
425
426 if ( $current_browser === $hide_on_browser ) {
427 return;
428 }
429 }
430
431 } elseif ( $display_condition === 'operating_system' ) {
432 $hide_on_os = ! empty( $settings['hide_on_os'] ) ? $settings['hide_on_os'] : 'none';
433
434 if ( $hide_on_os !== 'none' ) {
435 $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
436 $current_os = '';
437
438 if ( strpos( $user_agent, 'windows' ) !== false || strpos( $user_agent, 'win32' ) !== false || strpos( $user_agent, 'win64' ) !== false ) {
439 $current_os = 'windows';
440 } elseif ( strpos( $user_agent, 'macintosh' ) !== false || strpos( $user_agent, 'mac os x' ) !== false ) {
441 $current_os = 'macos';
442 } elseif ( strpos( $user_agent, 'linux' ) !== false && strpos( $user_agent, 'android' ) === false ) {
443 $current_os = 'linux';
444 } elseif ( strpos( $user_agent, 'android' ) !== false ) {
445 $current_os = 'android';
446 } elseif ( strpos( $user_agent, 'iphone' ) !== false || strpos( $user_agent, 'ipad' ) !== false || strpos( $user_agent, 'ipod' ) !== false ) {
447 $current_os = 'ios';
448 } elseif ( strpos( $user_agent, 'sunos' ) !== false ) {
449 $current_os = 'sunos';
450 } elseif ( strpos( $user_agent, 'openbsd' ) !== false ) {
451 $current_os = 'openbsd';
452 }
453
454 if ( $current_os === $hide_on_os ) {
455 return;
456 }
457 }
458 }
459 // ---- End Display Conditions ------------------------------------
460
461 $output = '';
462 $order_overview = 'on';
463 $order_details = 'on';
464 $billing_details = 'on';
465 $shipping_details = 'on';
466
467 if (isset($settings['enable_order_review']) && !empty($settings['enable_order_review']) ) {
468 $order_overview = $settings['enable_order_review'];
469 update_post_meta($this->post_id, '_wpfnl_thankyou_order_overview', $settings['enable_order_review']);
470 }else{
471 $order_overview = 'off';
472 update_post_meta( $this->post_id, '_wpfnl_thankyou_order_overview', 'off' );
473 }
474
475 if (isset($settings['enable_order_details']) && !empty($settings['enable_order_details']) ) {
476 $order_details = $settings['enable_order_details'];
477 update_post_meta($this->post_id, '_wpfnl_thankyou_order_details', $settings['enable_order_details']);
478 }else{
479 $order_details = 'off';
480 update_post_meta( $this->post_id, '_wpfnl_thankyou_order_details', 'off' );
481 }
482
483 if (isset($settings['enable_billing_details']) && !empty($settings['enable_billing_details']) ) {
484 $billing_details = $settings['enable_billing_details'];
485 update_post_meta($this->post_id, '_wpfnl_thankyou_billing_details', $settings['enable_billing_details']);
486 }else{
487 $billing_details = 'off';
488 update_post_meta( $this->post_id, '_wpfnl_thankyou_billing_details', 'off' );
489 }
490
491 if (isset($settings['enable_shipping_details']) && !empty($settings['enable_shipping_details']) ) {
492 $shipping_details = $settings['enable_shipping_details'];
493 update_post_meta($this->post_id, '_wpfnl_thankyou_shipping_details', $settings['enable_shipping_details']);
494 }else{
495 $shipping_details = 'off';
496 update_post_meta( $this->post_id, '_wpfnl_thankyou_shipping_details', 'off' );
497 }
498
499 // Build wrapper classes
500 $wrapper_classes = 'wpfnl-bricks-order-details-form';
501 $wrapper_classes .= ' wpfnl-bricks-display-order-overview-' . esc_attr( $order_overview );
502 $wrapper_classes .= ' wpfnl-bricks-display-order-details-' . esc_attr( $order_details );
503 $wrapper_classes .= ' wpfnl-bricks-display-billing-address-' . esc_attr( $billing_details );
504 $wrapper_classes .= ' wpfnl-bricks-display-shipping-address-' . esc_attr( $shipping_details );
505
506 // Add responsive classes
507 if ( ! empty( $settings['hide_on_desktop'] ) ) {
508 $wrapper_classes .= ' wpfnl-hide-desktop';
509 }
510 if ( ! empty( $settings['hide_on_tablet'] ) ) {
511 $wrapper_classes .= ' wpfnl-hide-tablet';
512 }
513 if ( ! empty( $settings['hide_on_mobile'] ) ) {
514 $wrapper_classes .= ' wpfnl-hide-mobile';
515 }
516
517 // Add animation class
518 $animation = ! empty( $settings['entrance_animation'] ) ? $settings['entrance_animation'] : '';
519 if ( $animation ) {
520 $wrapper_classes .= ' wpfnl-animation ' . esc_attr( $animation );
521 }
522
523 ?>
524 <?php if( !isset($_GET['optin']) ) {
525 ?>
526 <div class="<?php echo esc_attr( $wrapper_classes ); ?>">
527 <?php
528 echo do_shortcode( '[wpfunnels_order_details step_id='.$this->post_id.']' );
529 ?>
530 </div>
531 <?php }
532
533 }
534
535 }
536