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

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