PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.12
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.12
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 / admin / modules / steps / checkout / class-wpfnl-checkout.php

class-wpfnl-checkout.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.12, at admin/modules/steps/checkout/class-wpfnl-checkout.php

715 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checkout module
4 *
5 * @package
6 */
7
8 namespace WPFunnels\Admin\Modules\Steps\Checkout;
9
10 use WPFunnels\Admin\Modules\Steps\Module as Steps;
11 use WPFunnels\Metas\Wpfnl_Step_Meta_keys;
12 use WPFunnels\Wpfnl;
13 use WPFunnels\Wpfnl_functions;
14 use \WC_Subscriptions_Product;
15 use Wpfnl_Type_Factory;
16 class Module extends Steps
17 {
18 protected $validations;
19
20 protected $_internal_keys = [];
21
22 protected $type = 'checkout';
23
24 protected $prefix = '_wpfnl_checkout_';
25
26
27 public function __construct()
28 {
29 add_action('wp_ajax_order_bump_search_products', [$this, 'fetch_products']);
30 add_action('wp_ajax_wpfnl_replace_product_search', [$this, 'fetch_replace_products']);
31 add_action('wp_ajax_order_bump_search_coupons', [$this, 'fetch_coupons']);
32 add_action('wp_ajax_order_bump_search_categories', [$this, 'fetch_categories']);
33 add_action('wp_ajax_order_bump_search_tags', [$this, 'fetch_tags']);
34 add_action('wp_ajax_order_bump_search_shipping_methods', [$this, 'fetch_shipping_methods']);
35 add_action('wp_ajax_order_bump_search_countries', [$this, 'fetch_countries']);
36 add_action('wp_ajax_order_bump_search_checkout_pages', [$this, 'fetch_checkout_pages']);
37 add_action('wpfunnels/after_save_order_bump_data', [$this, 'update_elementor_data'], 10, 2);
38 }
39
40
41 public function get_validation_data()
42 {
43 return $this->validations;
44 }
45
46
47 public function init($id)
48 {
49 parent::init($id);
50 $this->set_internal_meta_value();
51 }
52
53
54 /**
55 * Load assets
56 *
57 * @param $hook
58 *
59 * @since 1.0.0
60 */
61 public function load_scripts($hook)
62 {
63 if (isset($_GET['step_id'])) {
64 $step_id = filter_input(INPUT_GET, 'step_id', FILTER_VALIDATE_INT);
65 if (Wpfnl_functions::check_if_this_is_step_type_by_id($step_id, 'checkout')) {
66 wp_enqueue_script($this->type . '-js', WPFNL_URL . 'admin/assets/dist/js/order-bump.min.js', ['jquery', 'wp-util'], '1.0.0', true);
67 wp_localize_script(
68 $this->type . '-js',
69 'CheckoutStep',
70 [
71 'ajaxurl' => esc_url_raw(admin_url('admin-ajax.php')),
72 'rest_api_url' => esc_url_raw(get_rest_url()),
73 'wc_currency' => get_woocommerce_currency_symbol(),
74 'nonce' => wp_create_nonce('wp_rest'),
75 'security' => wp_create_nonce('wpfnl-admin'),
76 'image_path' => WPFNL_URL . 'admin/assets/images',
77 'tooltipIcon' => WPFNL_URL . 'admin/partials/icons/question-tooltip-icon.php',
78 'imageUploadIcon' => WPFNL_URL . 'admin/partials/icons/image-upload-icon.php',
79 'step_id' => $step_id,
80 'back' => add_query_arg(
81 [
82 'page' => WPFNL_EDIT_FUNNEL_SLUG,
83 'id' => filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT),
84 'step_id' => $step_id,
85 ],
86 admin_url('admin.php')
87 )
88 ]
89 );
90 }
91 }
92 }
93
94
95 /**
96 * Init ajax hooks for
97 * saving metas
98 *
99 * @since 1.0.0
100 */
101 public function init_ajax()
102 {
103 $this->validations = [
104 'logged_in' => true,
105 'user_can' => 'wpf_manage_funnels',
106 ];
107 wp_ajax_helper()->handle('wpfnl-update-checkout-product-tab')
108 ->with_callback([$this, 'save_products'])
109 ->with_validation($this->validations);
110
111 }
112
113 /**
114 * Get view of the checkout settings page
115 *
116 * @since 1.0.0
117 */
118 public function get_view()
119 {
120 $is_pro_activated = Wpfnl_functions::is_wpfnl_pro_activated();
121 $show_settings = filter_input(INPUT_GET, 'show_settings', FILTER_SANITIZE_SPECIAL_CHARS);
122 $this->_internal_keys = Wpfnl_Step_Meta_keys::get_meta_keys($this->type);
123 $this->set_internal_meta_value();
124
125 if ($show_settings == 1) {
126 require_once WPFNL_DIR . '/admin/modules/steps/checkout/views/settings.php';
127 } else {
128 require_once WPFNL_DIR . '/admin/modules/steps/checkout/views/view.php';
129 }
130 }
131
132
133 /**
134 * Save products
135 *
136 * @param Array $payload
137 *
138 * @return Array
139 * @since 2.0.4
140 */
141 public function save_products($payload)
142 {
143 $step_id = $payload['step_id'];
144 $products = array();
145
146 if (isset($payload['products'])) {
147 $products = $payload['products'];
148 }
149
150 $funnel_id = get_post_meta($step_id,'_funnel_id',true);
151 $is_gbf = get_post_meta($funnel_id,'is_global_funnel',true);
152 $is_store_checkout = get_post_meta($funnel_id, '_wpfnl_funnel_type', true) === 'store_checkout';
153
154 $coupon = $payload['coupon'];
155 $isMultipleProduct = $payload['isMultipleProduct'];
156 $isQuantity = $payload['isQuantity'];
157
158 if ($coupon == 'true') {
159 $coupon = 'yes';
160 } else {
161 $coupon = 'no';
162 }
163
164 if ($isMultipleProduct == 'true') {
165 $isMultipleProduct = 'yes';
166 } else {
167 $isMultipleProduct = 'no';
168 }
169 if ($isQuantity == 'true') {
170 $isQuantity = 'yes';
171 } else {
172 $isQuantity = 'no';
173 }
174
175 if( isset($payload['enableAutoCoupon'], $payload['selectedCoupon'] ) ){
176 $autocoupon = [
177 'enableAutoCoupon' => $payload['enableAutoCoupon'],
178 'selectedCoupon' => $payload['selectedCoupon'],
179 ];
180 update_post_meta($step_id, '_wpfnl_checkout_auto_coupon', $autocoupon);
181 }
182
183 if( isset($payload['discountOptions']) ){
184 $discount = [
185 'discountOptions' => isset($payload['discountOptions']) ? $payload['discountOptions'] : 'original',
186 'discountapplyto' => isset($payload['discountapplyto']) && $payload['discountOptions'] != 'original' ? $payload['discountapplyto'] : '',
187 'mutedDiscountValue' => isset($payload['mutedDiscountValue']) && $payload['discountOptions'] != 'original' ? $payload['mutedDiscountValue'] : 0,
188 'discountedPrice' => isset($payload['discountedPrice']) && $payload['discountOptions'] != 'original' ? $payload['discountedPrice'] : 0,
189 ];
190 update_post_meta($step_id, '_wpfnl_checkout_discount_main_product', $discount);
191
192 if( isset($payload['timeBoundDiscount'])){
193 update_post_meta($step_id, '_wpfnl_time_bound_discount_settings', $payload['timeBoundDiscount']);
194 }
195 }
196
197 if( 'yes' == $is_gbf ){
198 return [
199 'success' => true,
200 'message' => 'Saved Successfully',
201 ];
202 }
203
204 if (!$products && !$is_store_checkout) {
205 return [
206 'success' => false,
207 'message' => 'No Product Found',
208 ];
209 }
210
211 foreach ($products as $pr_key => $pr_value) {
212 foreach ($pr_value as $key => $value) {
213 if ($key == 'price' || $key == 'image' || $key == 'title') {
214 unset($products[$pr_key][$key]);
215 }
216 }
217 }
218
219
220
221 update_post_meta($step_id, '_wpfnl_checkout_products', $products);
222 update_post_meta($step_id, '_wpfnl_checkout_coupon', $coupon);
223
224 $collapsible_coupon = isset($payload['collapsibleCoupon']) ? $payload['collapsibleCoupon'] : 'no';
225 if ($collapsible_coupon === 'true') {
226 $collapsible_coupon = 'yes';
227 } elseif ($collapsible_coupon != 'yes') {
228 $collapsible_coupon = 'no';
229 }
230 update_post_meta($step_id, '_wpfnl_checkout_collapsible_coupon', $collapsible_coupon);
231 update_post_meta($step_id, '_wpfnl_multiple_product', $isMultipleProduct);
232 update_post_meta($step_id, '_wpfnl_quantity_support', $isQuantity);
233
234 if( isset( $payload['quantityLimit'] ) ){
235 update_post_meta($step_id, '_wpfnl_quantity_limit', $payload['quantityLimit']);
236 }
237
238 if( isset( $payload['wpmlWidgetPosition'] ) ){
239 update_post_meta($step_id, '_wpfnl_wpml_Widget_Position_on_checkout', $payload['wpmlWidgetPosition']);
240 }
241
242 if( isset( $payload['disableGateways'] ) ){
243 update_post_meta($step_id, '_wpfnl_disabled_payemnts', $payload['disableGateways']);
244 }else{
245 update_post_meta($step_id, '_wpfnl_disabled_payemnts', [] );
246 }
247
248 // Save Product Options settings
249 if( isset( $payload['productOptions'] ) ){
250 update_post_meta($step_id, '_wpfnl_checkout_product_options', $payload['productOptions']);
251 }
252
253 return [
254 'success' => true,
255 'message' => 'Saved Successfully',
256 ];
257 }
258
259 /**
260 * Save checkout product tab
261 * data
262 *
263 * @param $payload
264 *
265 * @return array
266 */
267 public function checkout_update_product_tab_options($payload)
268 {
269
270 $step_id = sanitize_text_field($payload['step_id']);
271 unset($payload['step_id']);
272 $step = Wpfnl::get_instance()->step_store;
273 $step->set_id($step_id);
274 $this->_internal_keys = Wpfnl_Step_Meta_keys::get_meta_keys($this->type);
275 foreach ($payload as $key => $value) {
276 if (array_key_exists($this->prefix . $key, $this->_internal_keys)) {
277 switch ($key) {
278 case 'products':
279 $products = [];
280 if (!empty($value)) {
281 $saved_products = get_post_meta($step_id, '_wpfnl_checkout_products', true);
282 if ($saved_products) {
283 $saved_products[] = $value;
284 $products = $saved_products;
285 } else {
286 $products[] = $value;
287 }
288 }
289 $step->update_meta($step_id, $this->prefix . $key, $products);
290 break;
291 case 'discount':
292 $discount[] = $value;
293 $step->update_meta( $step_id, $this->prefix . $key, $discount );
294 break;
295 case 'coupon':
296 $coupon = $value;
297 $step->update_meta($step_id, $this->prefix . $key, $coupon);
298 break;
299 default:
300 $step->update_meta($step_id, $this->prefix . $key, $value);
301 break;
302 }
303 }
304 }
305 return [
306 'success' => true,
307 ];
308 }
309
310
311 /**
312 * Fetch product from WC data store
313 *
314 * @throws \Exception
315 * @since 1.0.0
316 */
317 public function fetch_products(){
318 check_ajax_referer('wpfnl-admin', 'security');
319 if (isset($_GET['term'])) {
320 $term = (string)esc_attr(wp_unslash($_GET['term']));
321 }
322 if (empty($term)) {
323 wp_die();
324 }
325
326 if( isset($_GET['isLearndash']) && $_GET['isLearndash'] == 'true' ){
327 $_class = 'lms';
328 }else{
329 $_class = 'wc';
330 }
331 $class_object = Wpfnl_Type_Factory::build($_class);
332 if( $class_object ){
333 $products = $class_object->retrieve_ob_item( $term );
334 }
335 wp_send_json($products);
336 }
337
338
339 /**
340 * Fetch product categories from WC
341 *
342 * @since 1.0.0
343 */
344 public function fetch_categories(){
345 check_ajax_referer('wpfnl-admin', 'security');
346
347 $term = isset($_GET['term']) ? (string)esc_attr(wp_unslash($_GET['term'])) : '';
348
349 if (empty($term)) {
350 wp_die();
351 }
352
353 $categories = [];
354
355 $args = [
356 'taxonomy' => 'product_cat',
357 'hide_empty' => false,
358 'search' => $term,
359 'number' => 50,
360 ];
361
362 $product_categories = get_terms($args);
363
364 if (!is_wp_error($product_categories) && !empty($product_categories)) {
365 foreach ($product_categories as $category) {
366 $categories[$category->term_id] = [
367 'id' => $category->term_id,
368 'name' => $category->name,
369 'slug' => $category->slug,
370 ];
371 }
372 }
373
374 wp_send_json($categories);
375 }
376
377
378 /**
379 * Fetch product tags from WC
380 *
381 * @since 1.0.0
382 */
383 public function fetch_tags(){
384 check_ajax_referer('wpfnl-admin', 'security');
385
386 $term = isset($_GET['term']) ? (string)esc_attr(wp_unslash($_GET['term'])) : '';
387
388 if (empty($term)) {
389 wp_die();
390 }
391
392 $tags = [];
393
394 $args = [
395 'taxonomy' => 'product_tag',
396 'hide_empty' => false,
397 'search' => $term,
398 'number' => 50,
399 ];
400
401 $product_tags = get_terms($args);
402
403 if (!is_wp_error($product_tags) && !empty($product_tags)) {
404 foreach ($product_tags as $tag) {
405 $tags[$tag->term_id] = [
406 'id' => $tag->term_id,
407 'name' => $tag->name,
408 'slug' => $tag->slug,
409 ];
410 }
411 }
412
413 wp_send_json($tags);
414 }
415
416
417 /**
418 * Fetch WooCommerce shipping methods
419 *
420 * @since 1.0.0
421 */
422 public function fetch_shipping_methods(){
423 check_ajax_referer('wpfnl-admin', 'security');
424
425 $term = isset($_GET['term']) ? (string)esc_attr(wp_unslash($_GET['term'])) : '';
426
427 if (empty($term)) {
428 wp_die();
429 }
430
431 $shipping_methods = [];
432
433 // Get all registered shipping methods
434 $wc_shipping = \WC_Shipping::instance();
435 $all_methods = $wc_shipping->get_shipping_methods();
436
437 foreach ($all_methods as $method_id => $method) {
438 $method_title = $method->get_method_title();
439
440 // Filter by search term
441 if (stripos($method_title, $term) !== false) {
442 $shipping_methods[] = [
443 'id' => $method_id,
444 'name' => $method_title,
445 ];
446 }
447 }
448
449 wp_send_json($shipping_methods);
450 }
451
452
453 /**
454 * Fetch countries from WooCommerce
455 *
456 * @since 1.0.0
457 */
458 public function fetch_countries(){
459 check_ajax_referer('wpfnl-admin', 'security');
460
461 $term = isset($_GET['term']) ? (string)esc_attr(wp_unslash($_GET['term'])) : '';
462
463 if (empty($term)) {
464 wp_die();
465 }
466
467 $countries = [];
468
469 // Get all WooCommerce countries
470 $wc_countries = WC()->countries->get_countries();
471
472 foreach ($wc_countries as $code => $name) {
473 // Filter by search term
474 if (stripos($name, $term) !== false || stripos($code, $term) !== false) {
475 $countries[] = [
476 'id' => $code,
477 'name' => $name,
478 ];
479 }
480 }
481
482 wp_send_json($countries);
483 }
484
485
486 /**
487 * Fetch WPFunnels checkout pages
488 *
489 * @since 1.0.0
490 */
491 public function fetch_checkout_pages(){
492 check_ajax_referer('wpfnl-admin', 'security');
493
494 $term = isset($_GET['term']) ? (string)esc_attr(wp_unslash($_GET['term'])) : '';
495
496 if (empty($term)) {
497 wp_die();
498 }
499
500 $checkout_pages = [];
501
502 // Query WPFunnels checkout steps
503 $args = [
504 'post_type' => 'wpfunnel_steps',
505 'post_status' => 'publish',
506 'posts_per_page' => 50,
507 's' => $term,
508 'meta_query' => [
509 [
510 'key' => '_step_type',
511 'value' => 'checkout',
512 'compare' => '='
513 ]
514 ]
515 ];
516
517 $query = new \WP_Query($args);
518 if ($query->have_posts()) {
519 while ($query->have_posts()) {
520 $query->the_post();
521 $checkout_pages[] = [
522 'id' => get_the_ID(),
523 'name' => get_the_title(),
524 ];
525 }
526 wp_reset_postdata();
527 }
528
529 wp_send_json($checkout_pages);
530 }
531
532
533 /**
534 * Fetch product from WC data store
535 *
536 * @throws \Exception
537 * @since 1.0.0
538 */
539 public function fetch_replace_products()
540 {
541
542 check_ajax_referer('wpfnl-admin', 'security');
543 if (isset($_GET['term'])) {
544 $term = (string)esc_attr(wp_unslash($_GET['term']));
545 }
546 if (empty($term)) {
547 wp_die();
548 }
549
550 $class_object = Wpfnl_Type_Factory::build('wc');
551 if( $class_object ){
552 $products = $class_object->retrieve_replace_ob_item( $term );
553 }
554 wp_send_json($products);
555 }
556
557
558 /**
559 * Fetch product from WC data store
560 *
561 * @throws \Exception
562 * @since 1.0.0
563 */
564 public function fetch_coupons()
565 {
566 check_ajax_referer('wpfnl-admin', 'security');
567 $term = (string)esc_attr(urldecode(wp_unslash($_GET['term'])));
568 $term = (string)wp_unslash($term);
569
570 if (empty($term)) {
571 wp_die();
572 }
573
574 $args = [
575 'posts_per_page' => -1,
576 'orderby' => 'title',
577 'order' => 'asc',
578 'post_type' => 'shop_coupon',
579 'post_status' => 'publish',
580 's' => $term,
581 ];
582 $coupons = get_posts($args);
583
584 $discount_types = wc_get_coupon_types();
585 $fetched_coupons = [];
586
587 if ($coupons) {
588 foreach ($coupons as $coupon) {
589 $discount_type = get_post_meta($coupon->ID, 'discount_type', true);
590 if (!empty($discount_types[$discount_type])) {
591 $fetched_coupons[$coupon->post_title] = $coupon->post_title;
592 }
593 }
594 }
595 wp_send_json($fetched_coupons);
596 }
597
598
599 /**
600 * This will regenerate the elementor data.
601 * This approach is not for programmers. Logic behind this code is We know position of WPFunnels widget - $path_array e.g. $path_array = array(0). This means
602 * position of WPFunnels widget will be $elementor_data[$key]['elements'][$path_array[0]]. if $path_array = array(0, 0), the position will be
603 * $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]. So we update the WPFunnels widget with new data ($settings) one by one manullay.
604 * This is a very bad approach. We will update the code soon.
605 *
606 * @param $key
607 * @param $elementor_data
608 * @param $settings
609 * @param $path_array
610 *
611 * @return mixed
612 * @since 2.0.0
613 */
614 private function regenerate_elementor_data($key, $elementor_data, $all_settings, $path_array)
615 {
616
617 foreach( $all_settings as $settings ){
618 $path_array_count = count($path_array);
619 if ($path_array_count == 1) {
620 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump_position'] = $settings['position'];
621 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump_layout'] = $settings['selectedStyle'];
622 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump_image']['url'] = $settings['productImage']['url'];
623 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump_image']['id'] = $settings['productImage']['id'];
624 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump_checkbox_label'] = $settings['checkBoxLabel'];
625 $elementor_data[$key]['elements'][$path_array[0]]['settings']['settings']['order_bump_product_detail_header'] = $settings['highLightText'];
626 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump_product_detail'] = $settings['productDescriptionText'];
627 $elementor_data[$key]['elements'][$path_array[0]]['settings']['order_bump'] = $settings['isEnabled'];
628 } elseif ($path_array_count == 2) {
629 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_position'] = $settings['position'];
630 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_layout'] = $settings['selectedStyle'];
631 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_image']['url'] = $settings['productImage']['url'];
632 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_image']['id'] = $settings['productImage']['id'];
633 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_checkbox_label'] = $settings['checkBoxLabel'];
634 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_product_detail_header'] = $settings['highLightText'];
635 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump_product_detail'] = $settings['productDescriptionText'];
636 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['settings']['order_bump'] = $settings['isEnabled'];
637 } elseif ($path_array_count == 3) {
638 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_position'] = $settings['position'];
639 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_layout'] = $settings['selectedStyle'];
640 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_image']['url'] = $settings['productImage']['url'];
641 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_image']['id'] = $settings['productImage']['id'];
642 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_checkbox_label'] = $settings['checkBoxLabel'];
643 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_product_detail_header'] = $settings['highLightText'];
644 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump_product_detail'] = $settings['productDescriptionText'];
645 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['settings']['order_bump'] = $settings['isEnabled'];
646 } elseif ($path_array_count == 4) {
647 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_position'] = $settings['position'];
648 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_layout'] = $settings['selectedStyle'];
649 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_image']['url'] = $settings['productImage']['url'];
650 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_image']['id'] = $settings['productImage']['id'];
651 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_checkbox_label'] = $settings['checkBoxLabel'];
652 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_product_detail_header'] = $settings['highLightText'];
653 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump_product_detail'] = $settings['productDescriptionText'];
654 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['settings']['order_bump'] = $settings['isEnabled'];
655 } elseif ($path_array_count == 5) {
656 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_position'] = $settings['position'];
657 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_layout'] = $settings['selectedStyle'];
658 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_image']['url'] = $settings['productImage']['url'];
659 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_image']['id'] = $settings['productImage']['id'];
660 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_checkbox_label'] = $settings['checkBoxLabel'];
661 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_product_detail_header'] = $settings['highLightText'];
662 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump_product_detail'] = $settings['productDescriptionText'];
663 $elementor_data[$key]['elements'][$path_array[0]]['elements'][$path_array[1]]['elements'][$path_array[2]]['elements'][$path_array[3]]['elements'][$path_array[4]]['settings']['order_bump'] = $settings['isEnabled'];
664 }
665 }
666 return $elementor_data;
667 }
668
669
670 /**
671 * This hook will trigger once the order bump data is saved from admin
672 *
673 * @param $post_id
674 * @param $settings
675 *
676 * @since 2.0.0
677 */
678 public function update_elementor_data($post_id, $all_settings)
679 {
680 if (Wpfnl_functions::get_builder_type() === 'elementor') {
681 $elementor_data = get_post_meta($post_id, '_elementor_data', true);
682 if ($elementor_data) {
683 if (is_array($elementor_data)) {
684 $elementor_data = $elementor_data;
685 } else {
686 $elementor_data = add_magic_quotes( json_decode( $elementor_data, true ) );
687 }
688
689
690 $el_data = array();
691 $checkout_widget = null;
692 foreach ($elementor_data as $key => $inner_element) {
693 $checkout_widget = Wpfnl_functions::recursive_multidimensional_ob_array_search_by_value('wpfnl-checkout', $inner_element['elements']);
694 if ($checkout_widget) {
695 $path_array = $checkout_widget['path'];
696
697 if (!$path_array) continue;
698
699 if ($path_array) {
700 $path = '';
701 $widget_settings = $checkout_widget['settings'];
702 $widget_settings['order_bump_checkbox_label'] = 'hukka hua';
703 $regenerated_elementor_data = $this->regenerate_elementor_data($key, $elementor_data, $all_settings, $path_array);
704 update_post_meta($post_id, '_elementor_data', $regenerated_elementor_data);
705 }
706 break;
707 }
708 }
709 }
710 }
711 }
712
713
714 }
715