PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.4
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.4
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / checkout / classes / class-cartflows-checkout-meta-data.php

class-cartflows-checkout-meta-data.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.4, at modules/checkout/classes/class-cartflows-checkout-meta-data.php

1,567 lines 50.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checkout post meta fields
4 *
5 * @package CartFlows
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 use CartflowsAdmin\AdminCore\Inc\AdminHelper;
13 /**
14 * Meta Boxes setup
15 */
16 class Cartflows_Checkout_Meta_Data extends Cartflows_Step_Meta_Base {
17
18
19 /**
20 * Instance
21 *
22 * @var $instance
23 */
24 private static $instance;
25
26
27 /**
28 * Initiator
29 */
30 public static function get_instance() {
31 if ( ! isset( self::$instance ) ) {
32 self::$instance = new self();
33 }
34
35 return self::$instance;
36 }
37
38 /**
39 * Constructor
40 */
41 public function __construct() {
42
43 add_filter( 'cartflows_admin_checkout_step_meta_fields', array( $this, 'filter_values' ), 10, 2 );
44
45 add_filter( 'cartflows_admin_checkout_step_meta_settings', array( $this, 'remove_store_checkout_product' ), 10, 2 );
46
47 // Step API data.
48 add_filter( 'cartflows_admin_checkout_step_data', array( $this, 'add_checkout_step_api_data' ), 10, 2 );
49 }
50
51 /**
52 * Add required data to api.
53 *
54 * @param array $api_data data.
55 * @param int $step_id step id.
56 */
57 public function add_checkout_step_api_data( $api_data, $step_id ) {
58
59 $field_data = $this->custom_fields_data( $step_id );
60 $api_data['custom_fields'] = $field_data;
61 $api_data['billing_fields'] = $field_data['billing_fields'];
62 $api_data['shipping_fields'] = $field_data['shipping_fields'];
63
64 return $api_data;
65 }
66
67 /**
68 * Removes settings tab checkout_product for store checkout
69 *
70 * @param array $settings prepared settings array.
71 * @param int $step_id current step id.
72 * @return array
73 * @since X.X.X
74 */
75 public function remove_store_checkout_product( $settings, $step_id ) {
76 $flow_id = absint( get_post_meta( $step_id, 'wcf-flow-id', true ) );
77
78 if ( absint( Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) ) === $flow_id && ! Cartflows_Helper::display_product_tab_in_store_checkout() ) {
79 unset( $settings['tabs']['products'] );
80 }
81
82 return $settings;
83 }
84
85
86 /**
87 * Filter checkout values
88 *
89 * @param array $options options.
90 * @param int $step_id post id.
91 */
92 public function filter_values( $options, $step_id ) {
93
94 if ( isset( $options['wcf-checkout-products'] ) ) {
95 // Update the product name in the option 'wcf-checkout-products'.
96 $checkout_products = $options['wcf-checkout-products'];
97
98 if ( is_array( $checkout_products ) && isset( $checkout_products[0] ) ) {
99
100 foreach ( $checkout_products as $index => $product ) {
101
102 $product_obj = wc_get_product( $product['product'] );
103 if ( $product_obj ) {
104 $checkout_products[ $index ]['name'] = $product_obj->get_name();
105 $checkout_products[ $index ]['img_url'] = get_the_post_thumbnail_url( $product['product'] );
106 $checkout_products[ $index ]['regular_price'] = Cartflows_Helper::get_product_original_price( $product_obj );
107 } else {
108 // Product or variation no longer exists — provide safe defaults so the editor doesn't crash.
109 $checkout_products[ $index ]['name'] = '';
110 $checkout_products[ $index ]['img_url'] = '';
111 $checkout_products[ $index ]['regular_price'] = '';
112 }
113 }
114 } else {
115 $checkout_products = array();
116 }
117
118 $options['wcf-checkout-products'] = $checkout_products;
119 }
120
121 if ( isset( $options['wcf_field_order_billing'] ) ) {
122 $options['wcf_field_order_billing'] = $this->get_field_settings( $step_id, 'billing', '' );
123 }
124
125 if ( isset( $options['wcf_field_order_shipping'] ) ) {
126 $options['wcf_field_order_shipping'] = $this->get_field_settings( $step_id, 'shipping', '' );
127 }
128
129 return $options;
130 }
131
132 /**
133 * Page Header Tabs
134 *
135 * @param int $step_id Post meta.
136 * @param array $options options.
137 */
138 public function get_settings( $step_id, $options = array() ) {
139
140 $common_tabs = $this->common_tabs();
141 $add_tabs = array(
142 'products' => array(
143 'title' => __( 'Products', 'cartflows' ),
144 'id' => 'products',
145 'class' => '',
146 'priority' => 10,
147 ),
148 'multi_order_bump' => array(
149 'title' => __( 'Order Bumps', 'cartflows' ),
150 'id' => 'order_bumps',
151 'class' => '',
152 'priority' => 20,
153 ),
154 'checkout_form_fields' => array(
155 'title' => __( 'Checkout Form', 'cartflows' ),
156 'id' => 'checkout_form_fields',
157 'class' => '',
158 'priority' => 40,
159 ),
160 'dynamic-offers' => array(
161 'title' => __( 'Dynamic Offers', 'cartflows' ),
162 'id' => 'dynamic-offers',
163 'class' => '',
164 'priority' => 50,
165 ),
166 'settings' => array(
167 'title' => __( 'Settings', 'cartflows' ),
168 'id' => 'settings',
169 'class' => '',
170 'priority' => 60,
171 ),
172 );
173
174 if ( _is_cartflows_pro() && 'enable' === Cartflows_Helper::get_common_settings()['pre_checkout_offer'] ) {
175
176 $add_tabs['checkout_offer'] = array(
177 'title' => __( 'Checkout Offer', 'cartflows' ),
178 'id' => 'checkout_offer',
179 'class' => '',
180 'priority' => 30,
181 );
182 }
183
184 $tabs = array_merge( $common_tabs, $add_tabs );
185 $settings = $this->get_settings_fields( $step_id );
186 $design_settings = $this->get_design_fields( $step_id );
187 $options = $this->get_data( $step_id );
188
189 return array(
190 'tabs' => $tabs,
191 'settings' => $settings,
192 'page_settings' => $this->get_page_settings( $step_id ),
193 'design_settings' => $design_settings,
194 );
195 }
196
197 /**
198 * Get design settings data.
199 *
200 * @param int $step_id Post ID.
201 */
202 public function get_design_fields( $step_id ) {
203
204 $options = $this->get_data( $step_id );
205 $layout_pro_option = array();
206
207 if ( ! _is_cartflows_pro() ) {
208 $layout_pro_option = array(
209 'two-step' => __( 'Two Step (Available in higher plan) ', 'cartflows' ),
210 'multistep-checkout' => __( 'Multistep Checkout (Available in higher plan) ', 'cartflows' ),
211 );
212 }
213
214 $settings = array(
215 'settings' => array(
216 'shortcode' => array(
217 'title' => __( 'Shortcode', 'cartflows' ),
218 'slug' => 'shortcodes',
219 'priority' => 10,
220 'conditions' => array(
221 'relation' => 'and',
222 'fields' => array(
223 array(
224 'name' => 'instant-layout-style',
225 'operator' => '!==',
226 'value' => 'yes',
227 ),
228 ),
229 ),
230 'fields' => array(
231 'checkout-shortcode' => array(
232 'type' => 'text',
233 'name' => 'checkout-shortcode',
234 'label' => __( 'CartFlows Checkout', 'cartflows' ),
235 'value' => '[cartflows_checkout]',
236 'help' => __( 'Add this shortcode to your checkout page', 'cartflows' ),
237 'readonly' => true,
238 'display_align' => 'vertical',
239 ),
240 ),
241 ),
242 'checkout-design' => array(
243 'title' => __( 'Checkout Design', 'cartflows' ),
244 'slug' => 'checkout_design',
245 'priority' => 20,
246 'fields' => array(
247 'checkout-skin' => array(
248 'type' => 'select',
249 'label' => __( 'Checkout Skin', 'cartflows' ),
250 'name' => 'wcf-checkout-layout',
251 'value' => $options['wcf-checkout-layout'],
252 'options' => array(
253 array(
254 'value' => 'modern-checkout',
255 'label' => esc_html__( 'Modern Checkout', 'cartflows' ),
256 ),
257 array(
258 'value' => 'modern-one-column',
259 'label' => esc_html__( 'Modern One Column', 'cartflows' ),
260 ),
261 array(
262 'value' => 'multistep-checkout',
263 'label' => esc_html__( 'Multistep Checkout', 'cartflows' ),
264 ),
265 array(
266 'value' => 'one-column',
267 'label' => esc_html__( 'One Column', 'cartflows' ),
268 ),
269 array(
270 'value' => 'two-column',
271 'label' => esc_html__( 'Two Column', 'cartflows' ),
272 ),
273 array(
274 'value' => 'two-step',
275 'label' => esc_html__( 'Two Step', 'cartflows' ),
276 ),
277
278 ),
279 'display_align' => 'vertical',
280 'pro_options' => $layout_pro_option,
281 'conditions' => array(
282 'relation' => 'and',
283 'fields' => array(
284 array(
285 'name' => 'instant-layout-style',
286 'operator' => '!==',
287 'value' => 'yes',
288 ),
289 ),
290 ),
291 ),
292 'primary-color' => array(
293 'type' => 'color-picker',
294 'name' => 'wcf-primary-color',
295 'label' => __( 'Primary Color', 'cartflows' ),
296 'value' => $options['wcf-primary-color'],
297 ),
298 'heading-font-family' => array(
299 'type' => 'font-family',
300 'label' => esc_html__( 'Font Family', 'cartflows' ),
301 'name' => 'wcf-base-font-family',
302 'value' => $options['wcf-base-font-family'],
303 'display_align' => 'vertical',
304 ),
305
306 'wcf-instant-checkout-section' => array(
307 'type' => 'heading',
308 'label' => __( 'Instant Checkout', 'cartflows' ),
309 'conditions' => array(
310 'relation' => 'and',
311 'fields' => array(
312 array(
313 'name' => 'instant-layout-style',
314 'operator' => '===',
315 'value' => 'yes',
316 ),
317 ),
318 ),
319 ),
320
321 'wcf-instant-checkout-left-side-bg-color' => array(
322 'type' => 'color-picker',
323 'label' => __( 'Left Column Background Color', 'cartflows' ),
324 'name' => 'wcf-instant-checkout-left-side-bg-color',
325 'value' => $options['wcf-instant-checkout-left-side-bg-color'],
326 'tooltip' => __( 'Pick a background color for the left side of your Checkout page.', 'cartflows' ),
327 'conditions' => array(
328 'relation' => 'and',
329 'fields' => array(
330 array(
331 'name' => 'instant-layout-style',
332 'operator' => '===',
333 'value' => 'yes',
334 ),
335 ),
336 ),
337 ),
338 'wcf-instant-checkout-right-side-bg-color' => array(
339 'type' => 'color-picker',
340 'label' => __( 'Right Column Background Color', 'cartflows' ),
341 'name' => 'wcf-instant-checkout-right-side-bg-color',
342 'value' => $options['wcf-instant-checkout-right-side-bg-color'],
343 'tooltip' => __( 'Pick a background color for the right side of your Checkout page.', 'cartflows' ),
344 'conditions' => array(
345 'relation' => 'and',
346 'fields' => array(
347 array(
348 'name' => 'instant-layout-style',
349 'operator' => '===',
350 'value' => 'yes',
351 ),
352 ),
353 ),
354 ),
355 ),
356 ),
357
358 'checkout-text-design' => array(
359 'title' => __( 'Checkout Texts & Buttons', 'cartflows' ),
360 'slug' => 'checkout_texts_buttons',
361 'priority' => 30,
362 'fields' => array(
363
364 'advanced-options' => array(
365 'type' => 'toggle',
366 'label' => __( 'Enable Advance Options', 'cartflows' ),
367 'name' => 'wcf-advance-options-fields',
368 'value' => $options['wcf-advance-options-fields'],
369 'is_fullwidth' => true,
370 ),
371
372 'heading-font-section' => array(
373 'type' => 'heading',
374 'label' => __( 'Heading Font', 'cartflows' ),
375 'conditions' => array(
376 'relation' => 'and',
377 'fields' => array(
378 array(
379 'name' => 'wcf-advance-options-fields',
380 'operator' => '===',
381 'value' => 'yes',
382 ),
383 ),
384 ),
385 ),
386 'heading-font-color' => array(
387 'type' => 'color-picker',
388 'label' => __( 'Heading Text Color', 'cartflows' ),
389 'name' => 'wcf-heading-color',
390 'value' => $options['wcf-heading-color'],
391 'conditions' => array(
392 'fields' => array(
393 array(
394 'name' => 'wcf-advance-options-fields',
395 'operator' => '===',
396 'value' => 'yes',
397 ),
398 ),
399 ),
400 ),
401 'heading-font-family' => array(
402 'type' => 'font-family',
403 'for' => 'wcf-heading',
404 'label' => esc_html__( 'Heading Font Family', 'cartflows' ),
405 'name' => 'wcf-heading-font-family',
406 'value' => $options['wcf-heading-font-family'],
407 'font_weight_name' => 'wcf-heading-font-weight',
408 'font_weight_value' => $options['wcf-heading-font-weight'],
409 'display_align' => 'vertical',
410 'conditions' => array(
411 'fields' => array(
412 array(
413 'name' => 'wcf-advance-options-fields',
414 'operator' => '===',
415 'value' => 'yes',
416 ),
417 ),
418 ),
419 ),
420
421 'input-field-section' => array(
422 'type' => 'heading',
423 'label' => __( 'Input Fields', 'cartflows' ),
424 'conditions' => array(
425 'relation' => 'and',
426 'fields' => array(
427 array(
428 'name' => 'wcf-advance-options-fields',
429 'operator' => '===',
430 'value' => 'yes',
431 ),
432 ),
433 ),
434 ),
435
436 'input-field-style' => array(
437 'type' => 'select',
438 'label' => __( 'Input Field Style', 'cartflows' ),
439 'name' => 'wcf-fields-skins',
440 'value' => 'style-one' === $options['wcf-fields-skins'] ? 'modern-label' : $options['wcf-fields-skins'],
441 'options' => array(
442 array(
443 'value' => 'default',
444 'label' => esc_html__( 'Default', 'cartflows' ),
445 ),
446 array(
447 'value' => 'modern-label',
448 'label' => esc_html__( 'Modern Labels', 'cartflows' ),
449 ),
450 ),
451 'conditions' => array(
452 'fields' => array(
453 array(
454 'name' => 'wcf-advance-options-fields',
455 'operator' => '===',
456 'value' => 'yes',
457 ),
458 ),
459 ),
460 'display_align' => 'vertical',
461 ),
462 'input-font-family' => array(
463 'type' => 'font-family',
464 'for' => 'wcf-input',
465 'label' => esc_html__( 'Input Field Font Family', 'cartflows' ),
466 'name' => 'wcf-input-font-family',
467 'value' => $options['wcf-input-font-family'],
468 'font_weight_name' => 'wcf-input-font-weight',
469 'font_weight_value' => $options['wcf-input-font-weight'],
470 'conditions' => array(
471 'fields' => array(
472 array(
473 'name' => 'wcf-advance-options-fields',
474 'operator' => '===',
475 'value' => 'yes',
476 ),
477 ),
478 ),
479 'display_align' => 'vertical',
480 ),
481
482 'input-size' => array(
483 'type' => 'select',
484 'label' => __( 'Field Size', 'cartflows' ),
485 'name' => 'wcf-input-field-size',
486 'value' => $options['wcf-input-field-size'],
487 'options' => array(
488 array(
489 'value' => '33px',
490 'label' => esc_html__( 'Extra Small', 'cartflows' ),
491 ),
492 array(
493 'value' => '38px',
494 'label' => esc_html__( 'Small', 'cartflows' ),
495 ),
496 array(
497 'value' => '44px',
498 'label' => esc_html__( 'Medium', 'cartflows' ),
499 ),
500 array(
501 'value' => '58px',
502 'label' => esc_html__( 'Large', 'cartflows' ),
503 ),
504 array(
505 'value' => '68px',
506 'label' => esc_html__( 'Extra Large', 'cartflows' ),
507 ),
508 array(
509 'value' => 'custom',
510 'label' => esc_html__( 'Custom', 'cartflows' ),
511 ),
512 ),
513 'conditions' => array(
514 'fields' => array(
515 array(
516 'name' => 'wcf-advance-options-fields',
517 'operator' => '===',
518 'value' => 'yes',
519 ),
520 ),
521 ),
522 'display_align' => 'vertical',
523 ),
524 'input-bottom-space' => array(
525 'type' => 'number',
526 'label' => __( 'Field Top-Bottom Spacing', 'cartflows' ),
527 'name' => 'wcf-field-tb-padding',
528 'value' => $options['wcf-field-tb-padding'],
529 'conditions' => array(
530 'fields' => array(
531 array(
532 'name' => 'wcf-input-field-size',
533 'operator' => '===',
534 'value' => 'custom',
535 ),
536 ),
537 ),
538 'display_align' => 'vertical',
539 ),
540 'input-right-space' => array(
541 'type' => 'number',
542 'label' => __( 'Field Left-Right Spacing', 'cartflows' ),
543 'name' => 'wcf-field-lr-padding',
544 'value' => $options['wcf-field-lr-padding'],
545 'conditions' => array(
546 'fields' => array(
547 array(
548 'name' => 'wcf-input-field-size',
549 'operator' => '===',
550 'value' => 'custom',
551 ),
552 ),
553 ),
554 'display_align' => 'vertical',
555 ),
556 'input-text/p-color' => array(
557 'type' => 'color-picker',
558 'label' => __( 'Field Text / Placeholder Color', 'cartflows' ),
559 'name' => 'wcf-field-color',
560 'value' => $options['wcf-field-color'],
561 'conditions' => array(
562 'fields' => array(
563 array(
564 'name' => 'wcf-advance-options-fields',
565 'operator' => '===',
566 'value' => 'yes',
567 ),
568 ),
569 ),
570 ),
571 'input-bg-color' => array(
572 'type' => 'color-picker',
573 'label' => __( 'Field Background Color', 'cartflows' ),
574 'name' => 'wcf-field-bg-color',
575 'value' => $options['wcf-field-bg-color'],
576 'conditions' => array(
577 'fields' => array(
578 array(
579 'name' => 'wcf-advance-options-fields',
580 'operator' => '===',
581 'value' => 'yes',
582 ),
583 ),
584 ),
585 ),
586 'input-border-color' => array(
587 'type' => 'color-picker',
588 'label' => __( 'Field Border Color', 'cartflows' ),
589 'name' => 'wcf-field-border-color',
590 'value' => $options['wcf-field-border-color'],
591 'conditions' => array(
592 'fields' => array(
593 array(
594 'name' => 'wcf-advance-options-fields',
595 'operator' => '===',
596 'value' => 'yes',
597 ),
598 ),
599 ),
600 ),
601 'input-label-color' => array(
602 'type' => 'color-picker',
603 'label' => __( 'Field Label Color', 'cartflows' ),
604 'name' => 'wcf-field-label-color',
605 'value' => $options['wcf-field-label-color'],
606 'conditions' => array(
607 'fields' => array(
608 array(
609 'name' => 'wcf-advance-options-fields',
610 'operator' => '===',
611 'value' => 'yes',
612 ),
613 ),
614 ),
615 ),
616
617 'button-field-section' => array(
618 'type' => 'heading',
619 'label' => __( 'Button Fields', 'cartflows' ),
620 'conditions' => array(
621 'relation' => 'and',
622 'fields' => array(
623 array(
624 'name' => 'wcf-advance-options-fields',
625 'operator' => '===',
626 'value' => 'yes',
627 ),
628 ),
629 ),
630 ),
631
632 'button-font-family' => array(
633 'type' => 'font-family',
634 'for' => 'wcf-button',
635 'label' => esc_html__( 'Button Font Family', 'cartflows' ),
636 'name' => 'wcf-button-font-family',
637 'value' => $options['wcf-button-font-family'],
638 'font_weight_name' => 'wcf-button-font-weight',
639 'font_weight_value' => $options['wcf-button-font-weight'],
640 'conditions' => array(
641 'fields' => array(
642 array(
643 'name' => 'wcf-advance-options-fields',
644 'operator' => '===',
645 'value' => 'yes',
646 ),
647 ),
648 ),
649 'display_align' => 'vertical',
650 ),
651
652 'button-font-size' => array(
653 'type' => 'select',
654 'label' => __( 'Button Size', 'cartflows' ),
655 'name' => 'wcf-input-button-size',
656 'value' => $options['wcf-input-button-size'],
657 'options' => array(
658 array(
659 'value' => '33px',
660 'label' => esc_html__( 'Extra Small', 'cartflows' ),
661 ),
662 array(
663 'value' => '38px',
664 'label' => esc_html__( 'Small', 'cartflows' ),
665 ),
666 array(
667 'value' => '44px',
668 'label' => esc_html__( 'Medium', 'cartflows' ),
669 ),
670 array(
671 'value' => '58px',
672 'label' => esc_html__( 'Large', 'cartflows' ),
673 ),
674 array(
675 'value' => '68px',
676 'label' => esc_html__( 'Extra Large', 'cartflows' ),
677 ),
678 array(
679 'value' => 'custom',
680 'label' => esc_html__( 'Custom', 'cartflows' ),
681 ),
682 ),
683 'conditions' => array(
684 'fields' => array(
685 array(
686 'name' => 'wcf-advance-options-fields',
687 'operator' => '===',
688 'value' => 'yes',
689 ),
690 ),
691 ),
692 'display_align' => 'vertical',
693 ),
694 'button-top-space' => array(
695 'type' => 'number',
696 'label' => __( 'Button Top-Bottom Spacing', 'cartflows' ),
697 'name' => 'wcf-submit-tb-padding',
698 'value' => $options['wcf-submit-tb-padding'],
699 'conditions' => array(
700 'fields' => array(
701 array(
702 'name' => 'wcf-input-button-size',
703 'operator' => '===',
704 'value' => 'custom',
705 ),
706 array(
707 'name' => 'wcf-advance-options-fields',
708 'operator' => '===',
709 'value' => 'yes',
710 ),
711 ),
712 ),
713 'display_align' => 'vertical',
714 ),
715 'button-left-space' => array(
716 'type' => 'number',
717 'label' => __( 'Button Left-Right Spacing', 'cartflows' ),
718 'name' => 'wcf-submit-lr-padding',
719 'value' => $options['wcf-submit-lr-padding'],
720 'conditions' => array(
721 'fields' => array(
722 array(
723 'name' => 'wcf-input-button-size',
724 'operator' => '===',
725 'value' => 'custom',
726 ),
727 array(
728 'name' => 'wcf-advance-options-fields',
729 'operator' => '===',
730 'value' => 'yes',
731 ),
732 ),
733 ),
734 'display_align' => 'vertical',
735 ),
736 'button-text-color' => array(
737 'type' => 'color-picker',
738 'label' => __( 'Button Text Color', 'cartflows' ),
739 'name' => 'wcf-submit-color',
740 'value' => $options['wcf-submit-color'],
741 'conditions' => array(
742 'fields' => array(
743 array(
744 'name' => 'wcf-advance-options-fields',
745 'operator' => '===',
746 'value' => 'yes',
747 ),
748 ),
749 ),
750 ),
751 'button-text-hover-color' => array(
752 'type' => 'color-picker',
753 'label' => __( 'Button Text Hover Color', 'cartflows' ),
754 'name' => 'wcf-submit-hover-color',
755 'value' => $options['wcf-submit-hover-color'],
756 'conditions' => array(
757 'fields' => array(
758 array(
759 'name' => 'wcf-advance-options-fields',
760 'operator' => '===',
761 'value' => 'yes',
762 ),
763 ),
764 ),
765 ),
766 'button-bg-color' => array(
767 'type' => 'color-picker',
768 'label' => __( 'Button Background Color', 'cartflows' ),
769 'name' => 'wcf-submit-bg-color',
770 'value' => $options['wcf-submit-bg-color'],
771 'conditions' => array(
772 'fields' => array(
773 array(
774 'name' => 'wcf-advance-options-fields',
775 'operator' => '===',
776 'value' => 'yes',
777 ),
778 ),
779 ),
780 ),
781 'button-bg-hover-color' => array(
782 'type' => 'color-picker',
783 'label' => __( 'Button Background Hover Color', 'cartflows' ),
784 'name' => 'wcf-submit-bg-hover-color',
785 'value' => $options['wcf-submit-bg-hover-color'],
786 'conditions' => array(
787 'fields' => array(
788 array(
789 'name' => 'wcf-advance-options-fields',
790 'operator' => '===',
791 'value' => 'yes',
792 ),
793 ),
794 ),
795 ),
796 'button-border-color' => array(
797 'type' => 'color-picker',
798 'label' => __( 'Button Border Color', 'cartflows' ),
799 'name' => 'wcf-submit-border-color',
800 'value' => $options['wcf-submit-border-color'],
801 'conditions' => array(
802 'fields' => array(
803 array(
804 'name' => 'wcf-advance-options-fields',
805 'operator' => '===',
806 'value' => 'yes',
807 ),
808 ),
809 ),
810 ),
811 'button-border-hover-color' => array(
812 'type' => 'color-picker',
813 'label' => __( 'Button Border Hover Color', 'cartflows' ),
814 'name' => 'wcf-submit-border-hover-color',
815 'value' => $options['wcf-submit-border-hover-color'],
816 'conditions' => array(
817 'fields' => array(
818 array(
819 'name' => 'wcf-advance-options-fields',
820 'operator' => '===',
821 'value' => 'yes',
822 ),
823 ),
824 ),
825 ),
826
827 'highlighted-area' => array(
828 'type' => 'color-picker',
829 'label' => __( 'Section Background Color', 'cartflows' ),
830 'name' => 'wcf-hl-bg-color',
831 'value' => $options['wcf-hl-bg-color'],
832 'conditions' => array(
833 'fields' => array(
834 array(
835 'name' => 'wcf-advance-options-fields',
836 'operator' => '===',
837 'value' => 'yes',
838 ),
839 ),
840 ),
841 'tooltip' => __( 'Change the background color of the payment description box to match your style.', 'cartflows' ),
842 ),
843 ),
844 ),
845 ),
846 );
847
848 $flow_id = absint( get_post_meta( $step_id, 'wcf-flow-id', true ) );
849
850 $settings = apply_filters( 'cartflows_admin_checkout_design_fields', $settings, $options, $flow_id );
851 return $settings;
852 }
853
854 /**
855 * Get dummy settings for product options.
856 */
857 public function get_dummy_settings_for_product_options() {
858 return array(
859 'wcf-enable-product-options' => array(
860 'type' => 'checkbox',
861 'label' => __( 'Enable Product Options', 'cartflows' ),
862 ),
863 'wcf-get-product-option-fields' => array(
864 'type' => 'product-options',
865 'label' => __( 'Enable Product Options', 'cartflows' ),
866 ),
867
868 'wcf-product-options' => array(
869 'type' => 'radio',
870 'label' => __( 'Enable Conditions', 'cartflows' ),
871 'options' => array(
872 array(
873 'value' => 'force-all',
874 'label' => __( 'Restrict User to Purchase All Products', 'cartflows' ),
875 ),
876 array(
877 'value' => 'single-selection',
878 'label' => __( 'Let User Select One Product from All Options', 'cartflows' ),
879 ),
880 array(
881 'value' => 'multiple-selection',
882 'label' => __( 'Let User Select Multiple Products from All Options', 'cartflows' ),
883 ),
884 ),
885 ),
886 'enable-variation' => array(
887 'type' => 'checkbox',
888 'label' => __( 'Enable Variations', 'cartflows' ),
889 ),
890 'wcf-product-variation-options' => array(
891 'type' => 'radiofield',
892 'label' => '',
893 'child_class' => 'wcf-child-field',
894 'options' => array(
895 array(
896 'value' => 'inline',
897 'label' => __( 'Show Variations Inline', 'cartflows' ),
898 ),
899 array(
900 'value' => 'popup',
901 'label' => __( 'Show Variations in Popup', 'cartflows' ),
902 ),
903 ),
904 ),
905 'wcf-enable-product-quantity' => array(
906 'type' => 'checkbox',
907 'label' => __( 'Enable Quantity', 'cartflows' ),
908 ),
909
910 );
911 }
912
913 /**
914 * Get dummy settings for product options.
915 */
916 public function get_dummy_settings_for_coupon() {
917 return array(
918 'coupon' => array(
919 'type' => 'coupon',
920 'label' => __( 'Select Coupon', 'cartflows' ),
921 'placeholder' => __( 'Search for a coupon', 'cartflows' ),
922 'multiple' => false,
923 'allow_clear' => true,
924 /* translators: %1$1s: link html start, %2$12: link html end*/
925 'desc' => sprintf( __( 'For more information about the CartFlows coupon please %1$1s Click here.%2$2s', 'cartflows' ), '<a href="' . esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/enable-coupons-on-cartflows-page/' ) ) . '" class="!text-gray-600" target="_blank">', '</a>' ),
926 ),
927
928 );
929 }
930
931 /**
932 * Get page settings.
933 *
934 * @param int $step_id Step ID.
935 */
936 public function get_page_settings( $step_id ) {
937
938 $options = $this->get_data( $step_id );
939
940 $settings = array(
941 'settings' => array(
942 'product' => array(
943 'tab' => 'products',
944 'slug' => 'product',
945 'title' => __( 'Products', 'cartflows' ),
946 'priority' => 20,
947 'fields' => array(
948 'wcf-checkout-products' => array(
949 'type' => 'product-repeater',
950 'fieldtype' => 'product',
951 'name' => 'wcf-checkout-products',
952 'value' => array(),
953 'label' => __( 'Select Product', 'cartflows' ),
954 'placeholder' => __( 'Search for a product...', 'cartflows' ),
955 'multiple' => false,
956 'allow_clear' => true,
957 'allowed_product_types' => array(),
958 'excluded_product_types' => array( 'grouped' ),
959 'include_product_types' => array( 'braintree-subscription, braintree-variable-subscription' ),
960 ),
961 'checkout-product-doc' => array(
962 'type' => 'doc',
963 'icon' => 'info',
964 /* translators: %1$1s: link html start, %2$12: link html end*/
965 'content' => sprintf( __( 'For more information about the checkout product settings please %1$1s Click here.%2$2s', 'cartflows' ), '<a href="' . esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/set-product-quantity-and-discount/' ) ) . '" target="_blank">', '</a>' ),
966 ),
967 ),
968 ),
969
970 'coupon' => array(
971 'tab' => 'products',
972 'slug' => 'coupon',
973 'title' => __( 'Auto Apply Coupon', 'cartflows' ),
974 'priority' => 30,
975 'fields' => _is_cartflows_pro() && 'Activated' === _is_cartflows_pro_license_activated() ? '' : $this->get_dummy_settings_for_coupon(),
976
977 ),
978 // Product Options.
979 'product-options' => array(
980 'tab' => 'products',
981 'slug' => 'product-options',
982 'title' => __( 'Product Options', 'cartflows' ),
983 'priority' => 40,
984 'fields' => _is_cartflows_pro() && 'Activated' === _is_cartflows_pro_license_activated() ? '' : $this->get_dummy_settings_for_product_options(),
985 ),
986
987 // checkout offer.
988 'checkout-offer' => array(
989 'tab' => 'checkout_offer',
990 'slug' => 'checkout-offer',
991 'title' => __( 'Checkout Offer', 'cartflows' ),
992 'priority' => 60,
993 'fields' => ! _is_cartflows_pro() ? array(
994 'checkout-offer' => array(
995 'type' => 'pro-notice',
996 'feature' => 'Checkout Offer',
997 ),
998 )
999 : '',
1000 ),
1001
1002 ),
1003 );
1004
1005 $settings = apply_filters( 'cartflows_admin_checkout_meta_fields', $settings, $step_id, $options );
1006
1007 return $settings;
1008 }
1009 /**
1010 * Get settings data.
1011 *
1012 * @param int $step_id Post ID.
1013 */
1014 public function get_settings_fields( $step_id ) {
1015
1016 $options = $this->get_data( $step_id );
1017
1018 // Determine whether to show CodeMirror editors or the legacy textarea.
1019 $show_code_editor = AdminHelper::should_show_code_editor();
1020
1021 $general_fields = array(
1022 'slug' => array(
1023 'type' => 'text',
1024 'name' => 'step_post_name',
1025 'label' => __( 'Step Slug', 'cartflows' ),
1026 'value' => get_post_field( 'post_name' ),
1027 'display_align' => 'vertical',
1028 'tooltip' => __( 'This is the name (slug) of the current step. Changing it will update the URL for this step, so be cautious!', 'cartflows' ),
1029 ),
1030 'wcf-disable-step-toggle' => array(
1031 'type' => 'toggle',
1032 'label' => __( 'Disable Step', 'cartflows' ),
1033 'name' => 'wcf-disable-step',
1034 'value' => $options['wcf-disable-step'],
1035 'tooltip' => __( 'Turn this on to disable the step', 'cartflows' ),
1036 'is_fullwidth' => true,
1037 ),
1038 );
1039
1040 if ( $show_code_editor ) {
1041 // Migration completed: show separate JS and CSS CodeMirror editors.
1042 $general_fields['wcf-checkout-custom-js'] = array(
1043 'type' => 'code',
1044 'label' => __( 'Custom JavaScript', 'cartflows' ),
1045 'name' => 'wcf-step-custom-js',
1046 'value' => $options['wcf-step-custom-js'],
1047 'display_align' => 'vertical',
1048 'language' => 'javascript',
1049 'tooltip' => __( 'Add your own custom JavaScript code here. Do not include script tags.', 'cartflows' ),
1050 );
1051 $general_fields['wcf-checkout-custom-css'] = array(
1052 'type' => 'code',
1053 'label' => __( 'Custom CSS', 'cartflows' ),
1054 'name' => 'wcf-step-custom-css',
1055 'value' => $options['wcf-step-custom-css'],
1056 'display_align' => 'vertical',
1057 'language' => 'css',
1058 'tooltip' => __( 'Add your own custom CSS code here. Do not include style tags.', 'cartflows' ),
1059 );
1060 } else {
1061 // Migration not completed: show the legacy combined textarea.
1062 $general_fields['wcf-checkout-custom-script'] = array(
1063 'type' => 'textarea',
1064 'label' => __( 'Custom Script', 'cartflows' ),
1065 'name' => 'wcf-custom-script',
1066 'value' => $options['wcf-custom-script'],
1067 'display_align' => 'vertical',
1068 'tooltip' => __( 'Add your own custom code here. If you\'re adding CSS, make sure to wrap it inside &lt;style&gt; tags.', 'cartflows' ),
1069 );
1070 }
1071
1072 $settings = array(
1073 'settings' => array(
1074 'general' => array(
1075 'title' => __( 'General', 'cartflows' ),
1076 'slug' => 'general',
1077 'priority' => 20,
1078 'fields' => $general_fields,
1079 ),
1080 'advanced' => array(
1081 'title' => esc_html__( 'Advanced', 'cartflows' ),
1082 'slug' => 'advanced',
1083 'priority' => 10,
1084 'fields' => array(
1085 'wcf-show-prod-img-order-review' => array(
1086 'type' => 'toggle',
1087 'label' => __( 'Display Product Images', 'cartflows' ),
1088 'name' => 'wcf-order-review-show-product-images',
1089 'value' => $options['wcf-order-review-show-product-images'],
1090 'tooltip' => __( 'Turn this ON to show your product images in the order review section.', 'cartflows' ),
1091 'is_fullwidth' => true,
1092 ),
1093 'wcf-edit-cart' => array(
1094 'type' => 'toggle',
1095 'label' => __( 'Enable Cart Editing on Checkout', 'cartflows' ),
1096 'name' => 'wcf-remove-product-field',
1097 'value' => $options['wcf-remove-product-field'],
1098 'tooltip' => __( 'Users can easily remove products from the checkout page if they decide not to purchase them.', 'cartflows' ),
1099 'is_fullwidth' => true,
1100 ),
1101 ),
1102 ),
1103 ),
1104 );
1105
1106 if ( wcf_show_deprecated_step_notes() ) {
1107 $settings['settings']['general']['fields']['step-note'] = array(
1108 'type' => 'textarea',
1109 'name' => 'wcf-step-note',
1110 'label' => __( 'Step Note', 'cartflows' ),
1111 'value' => get_post_meta( $step_id, 'wcf-step-note', true ),
1112 'rows' => 2,
1113 'cols' => 38,
1114 'display_align' => 'vertical',
1115 );
1116 }
1117
1118 return apply_filters( 'cartflows_admin_checkout_settings_fields', $settings );
1119 }
1120
1121 /**
1122 * Get data.
1123 *
1124 * @param int $step_id Post ID.
1125 */
1126 public function get_data( $step_id ) {
1127
1128 $optin_data = array();
1129
1130 // Stored data.
1131 $stored_meta = get_post_meta( $step_id );
1132
1133 // Default.
1134 $default_data = self::get_meta_option( $step_id );
1135
1136 // Set stored and override defaults.
1137 foreach ( $default_data as $key => $value ) {
1138 if ( array_key_exists( $key, $stored_meta ) ) {
1139 $optin_data[ $key ] = ( isset( $stored_meta[ $key ][0] ) ) ? maybe_unserialize( $stored_meta[ $key ][0] ) : '';
1140 } else {
1141 $optin_data[ $key ] = ( isset( $default_data[ $key ]['default'] ) ) ? $default_data[ $key ]['default'] : '';
1142 }
1143 }
1144
1145 return $optin_data;
1146 }
1147
1148 /**
1149 * Get meta.
1150 *
1151 * @param int $post_id Post ID.
1152 */
1153 public static function get_meta_option( $post_id ) {
1154
1155 $meta_option = wcf()->options->get_checkout_fields( $post_id );
1156
1157 return $meta_option;
1158 }
1159
1160 /**
1161 * Get name.
1162 *
1163 * @param int $id Product ID.
1164 */
1165 public static function get_name( $id ) {
1166
1167 $product_object = wc_get_product( $id );
1168
1169 $formatted_name = '';
1170
1171 if ( is_object( $product_object ) ) {
1172 $formatted_name = rawurldecode( $product_object->get_formatted_name() );
1173 }
1174 return $formatted_name;
1175 }
1176
1177 /**
1178 * Add custom meta fields
1179 *
1180 * @param int $post_id post id.
1181 */
1182 public function custom_fields_data( $post_id ) {
1183
1184 $billing_fields = $this->get_field_settings( $post_id, 'billing', '' );
1185 $shipping_fields = $this->get_field_settings( $post_id, 'shipping', '' );
1186
1187 $options = $this->get_data( $post_id );
1188
1189 $custom_fields = array(
1190 'extra_fields' => array(
1191 'title' => __( 'Form Settings', 'cartflows' ),
1192 'priority' => 10,
1193 'fields' => array(
1194 'enable-coupon-field' => array(
1195 'type' => 'toggle',
1196 'label' => __( 'Enable Coupon Field', 'cartflows' ),
1197 'name' => 'wcf-show-coupon-field',
1198 'is_fullwidth' => true,
1199 ),
1200 'collapse-coupon-field' => array(
1201 'type' => 'toggle',
1202 'label' => __( 'Collapsible Coupon Field', 'cartflows' ),
1203 'name' => 'wcf-optimize-coupon-field',
1204 'child_class' => 'wcf-cfe-child',
1205 'is_fullwidth' => true,
1206 'conditions' => array(
1207 'fields' => array(
1208 array(
1209 'name' => 'wcf-show-coupon-field',
1210 'operator' => '===',
1211 'value' => 'yes',
1212 ),
1213 ),
1214 ),
1215 ),
1216 'enable-additional-field' => array(
1217 'type' => 'toggle',
1218 'label' => __( 'Enable Additional Field', 'cartflows' ),
1219 'name' => 'wcf-checkout-additional-fields',
1220 'is_fullwidth' => true,
1221 ),
1222 'collapse-additional-field' => array(
1223 'type' => 'toggle',
1224 'label' => __( 'Collapsible Additional Field', 'cartflows' ),
1225 'name' => 'wcf-optimize-order-note-field',
1226 'child_class' => 'wcf-cfe-child',
1227 'is_fullwidth' => true,
1228 'conditions' => array(
1229 'fields' => array(
1230 array(
1231 'name' => 'wcf-checkout-additional-fields',
1232 'operator' => '===',
1233 'value' => 'yes',
1234 ),
1235 ),
1236 ),
1237 ),
1238 'shipping-field' => array(
1239 'type' => 'toggle',
1240 'label' => __( 'Enable Ship To Different Address', 'cartflows' ),
1241 'name' => 'wcf-shipto-diff-addr-fields',
1242 'is_fullwidth' => true,
1243 ),
1244
1245 'wcf-google-autoaddress' => array(
1246 'type' => 'toggle',
1247 'label' => __( 'Enable Google Address Autocomplete', 'cartflows' ),
1248 'name' => 'wcf-google-autoaddress',
1249 /* translators: %1$s: link html start, %2$s: link html end*/
1250 'desc' => __( 'Before enabling this option, make sure that you have added API key in Google Address Autocomplete Settings.', 'cartflows' ),
1251 'is_fullwidth' => true,
1252 ),
1253 'wcf-no-shipping-method-message-toggle' => array(
1254 'type' => 'toggle',
1255 'label' => __( 'Enable Custom Shipping Message', 'cartflows' ),
1256 'name' => 'wcf-custom-no-shipping-method-message-toggle',
1257 'value' => $options['wcf-custom-no-shipping-method-message-toggle'],
1258 'is_fullwidth' => true,
1259 'tooltip' => __( 'Turn this on to show a custom message when no shipping options are available at checkout.', 'cartflows' ),
1260 ),
1261 'wcf-no-shipping-method-message' => array(
1262 'type' => 'textarea',
1263 'label' => __( 'Shipping Message', 'cartflows' ),
1264 'name' => 'wcf-no-shipping-method-message',
1265 'value' => $options['wcf-no-shipping-method-message'],
1266 'placeholder' => __( 'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'cartflows' ),
1267 'tooltip' => __( 'This message will be displayed when no shipping method is available.', 'cartflows' ),
1268 'rows' => 2,
1269 'cols' => 38,
1270 'display_align' => 'vertical',
1271 'conditions' => array(
1272 'fields' => array(
1273 array(
1274 'name' => 'wcf-custom-no-shipping-method-message-toggle',
1275 'operator' => '===',
1276 'value' => 'yes',
1277 ),
1278 ),
1279 ),
1280 ),
1281 'order-review-summary-position' => array(
1282 'type' => 'select',
1283 'name' => 'wcf-order-review-summary-position',
1284 'label' => __( 'Order Summary Position', 'cartflows' ),
1285 'display_align' => 'vertical',
1286 'value' => $options['wcf-order-review-summary-position'],
1287 'tooltip' => __( 'Choose this option to adjust where the order summary appears on mobile devices.', 'cartflows' ),
1288 'options' => array(
1289 array(
1290 'value' => 'top',
1291 'label' => __( 'Top', 'cartflows' ),
1292 ),
1293 array(
1294 'value' => 'bottom',
1295 'label' => __( 'Bottom', 'cartflows' ),
1296 ),
1297 ),
1298 ),
1299 ),
1300 ),
1301 'billing_fields' => array(
1302 'fields' => $billing_fields,
1303 ),
1304 'shipping_fields' => array(
1305 'fields' => $shipping_fields,
1306 ),
1307 // Checkout Fields.
1308 'checkout_settings' => array(
1309 'title' => __( 'Form Headings', 'cartflows' ),
1310 'slug' => 'checkout_setting',
1311 'priority' => 20,
1312 'fields' => array(
1313
1314 'wcf-billing-details-text' => array(
1315 'type' => 'text',
1316 'label' => __( 'Billing Details', 'cartflows' ),
1317 'name' => 'wcf-checkout-billing-details-text',
1318 'placeholder' => __( 'Billing details', 'cartflows' ),
1319 'display_align' => 'vertical',
1320 ),
1321 'wcf-shipping-details-text' => array(
1322 'type' => 'text',
1323 'label' => __( 'Shipping Details', 'cartflows' ),
1324 'name' => 'wcf-checkout-shipping-details-text',
1325 'placeholder' => __( 'Ship to a different address?', 'cartflows' ),
1326 'display_align' => 'vertical',
1327 ),
1328 'wcf-your-order-text' => array(
1329 'type' => 'text',
1330 'label' => __( 'Your Order', 'cartflows' ),
1331 'name' => 'wcf-checkout-your-order-text',
1332 'placeholder' => __( 'Your order', 'cartflows' ),
1333 'display_align' => 'vertical',
1334 ),
1335 'wcf-customer-info-text' => array(
1336 'type' => 'text',
1337 'label' => __( 'Customer Information', 'cartflows' ),
1338 'name' => 'wcf-checkout-customer-info-text',
1339 'placeholder' => __( 'Customer information', 'cartflows' ),
1340 'tooltip' => __( 'This heading will only appear when you use the Modern Checkout style.', 'cartflows' ),
1341 'display_align' => 'vertical',
1342 ),
1343 'wcf-payment-text' => array(
1344 'type' => 'text',
1345 'label' => __( 'Payment', 'cartflows' ),
1346 'name' => 'wcf-checkout-payment-text',
1347 'placeholder' => __( 'Payment', 'cartflows' ),
1348 'tooltip' => __( 'This heading will only appear when you use the Modern Checkout style.', 'cartflows' ),
1349 'display_align' => 'vertical',
1350 ),
1351 'wcf-enable-validation-text' => array(
1352 'type' => 'toggle',
1353 'label' => __( 'Enable Field Validation Error Message', 'cartflows' ),
1354 'name' => 'wcf-enable-checkout-field-validation-text',
1355 'value' => $options['wcf-enable-checkout-field-validation-text'],
1356 'tooltip' => __( 'This message will appear next to the field name to show an error if something goes wrong.', 'cartflows' ),
1357 'is_fullwidth' => true,
1358 ),
1359 'wcf-field-validation-text' => array(
1360 'type' => 'text',
1361 'label' => __( 'Validation Error Message', 'cartflows' ),
1362 'name' => 'wcf-checkout-field-validation-text',
1363 'placeholder' => __( 'is required', 'cartflows' ),
1364 'display_align' => 'vertical',
1365 'conditions' => array(
1366 'fields' => array(
1367 array(
1368 'name' => 'wcf-enable-checkout-field-validation-text',
1369 'operator' => '===',
1370 'value' => 'yes',
1371 ),
1372 ),
1373 ),
1374 ),
1375 ),
1376 ),
1377 // Checkout Fields.
1378 'button_settings' => array(
1379 'title' => __( 'Place Order Button', 'cartflows' ),
1380 'slug' => 'button_settings',
1381 'priority' => 20,
1382 'fields' => array(
1383 'wcf-place-order-button-text' => array(
1384 'type' => 'text',
1385 'label' => __( 'Button Text', 'cartflows' ),
1386 'name' => 'wcf-checkout-place-order-button-text',
1387 'value' => $options['wcf-checkout-place-order-button-text'],
1388 'placeholder' => __( 'Place Order', 'cartflows' ),
1389 'tooltip' => __( 'Customizes the text on the \'Place Order\' button during checkout, allowing you to make it more relevant to your customers.', 'cartflows' ),
1390 'display_align' => 'vertical',
1391 ),
1392 'wcf-place-order-button-icon' => array(
1393 'type' => 'toggle',
1394 'label' => __( 'Enable Lock Icon', 'cartflows' ),
1395 'name' => 'wcf-checkout-place-order-button-lock',
1396 'value' => $options['wcf-checkout-place-order-button-lock'],
1397 'tooltip' => __( 'Enabling this will add a lock icon to the \'Place Order\' button on the checkout page, indicating secure payment processing.', 'cartflows' ),
1398 'is_fullwidth' => true,
1399 ),
1400
1401 'wcf-place-order-price-display' => array(
1402 'type' => 'toggle',
1403 'label' => __( 'Enable Price Display', 'cartflows' ),
1404 'name' => 'wcf-checkout-place-order-button-price-display',
1405 'value' => $options['wcf-checkout-place-order-button-price-display'],
1406 'tooltip' => __( 'This will display the total amount in the cart when you click the \'Place Order\' button.', 'cartflows' ),
1407 'is_fullwidth' => true,
1408 ),
1409 ),
1410 ),
1411 );
1412
1413 $custom_fields = apply_filters( 'cartflows_admin_checkout_editor_settings', $custom_fields );
1414
1415 return $custom_fields;
1416 }
1417
1418 /**
1419 * Add custom meta fields
1420 *
1421 * @param string $post_id post id.
1422 * @param array $fields fields.
1423 * @param array $new_fields new fields.
1424 */
1425 public function get_field_settings( $post_id, $fields, $new_fields ) {
1426
1427 if ( 'billing' === $fields ) {
1428 $get_ordered_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
1429 } else {
1430 $get_ordered_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
1431 }
1432
1433 if ( isset( $get_ordered_fields ) && ! empty( $get_ordered_fields ) ) {
1434 $data_array = $get_ordered_fields;
1435
1436 } else {
1437 $data_array = Cartflows_Helper::get_checkout_fields( $fields, $post_id );
1438 }
1439
1440 if ( isset( $new_fields ) && ! empty( $new_fields ) && is_array( $new_fields ) ) {
1441 $data_array = $new_fields;
1442 }
1443 $field_args = array();
1444
1445 foreach ( $data_array as $key => $value ) {
1446
1447 $field_args = $this->prepare_field_arguments( $key, $value, $post_id, $fields );
1448
1449 foreach ( $field_args as $arg_key => $arg_val ) {
1450
1451 if ( ! in_array( $arg_key, $value, true ) ) {
1452
1453 $data_array[ $key ][ $arg_key ] = $arg_val;
1454 }
1455 }
1456
1457 $data_array[ $key ] = Cartflows_Helper::get_instance()->prepare_custom_field_settings( $data_array[ $key ], $key, $field_args, $fields, 'checkout' );
1458 }
1459
1460 return $data_array;
1461 }
1462
1463 /**
1464 * Fetch default width of checkout fields by key.
1465 *
1466 * @param string $checkout_field_key field key.
1467 * @return int
1468 */
1469 public function get_default_checkout_field_width( $checkout_field_key ) {
1470
1471 $default_width = 100;
1472 switch ( $checkout_field_key ) {
1473 case 'billing_first_name':
1474 case 'billing_last_name':
1475 case 'billing_address_1':
1476 case 'billing_address_2':
1477 case 'shipping_first_name':
1478 case 'shipping_last_name':
1479 case 'shipping_address_1':
1480 case 'shipping_address_2':
1481 $default_width = 50;
1482 break;
1483
1484 case 'billing_city':
1485 case 'billing_state':
1486 case 'billing_postcode':
1487 case 'shipping_city':
1488 case 'shipping_state':
1489 case 'shipping_postcode':
1490 $default_width = 33;
1491 break;
1492
1493 default:
1494 $default_width = 100;
1495 break;
1496 }
1497
1498 return $default_width;
1499 }
1500
1501
1502 /**
1503 * Prepare HTML data for billing and shipping fields.
1504 *
1505 * @param string $field checkout field key.
1506 * @param array $field_data checkout field object.
1507 * @param integer $post_id chcekout post id.
1508 * @param string $type checkout field type.
1509 * @return array
1510 */
1511 public function prepare_field_arguments( $field, $field_data, $post_id, $type ) {
1512
1513 if ( isset( $field_data['label'] ) ) {
1514 $field_name = $field_data['label'];
1515 } elseif ( 'shipping_address_2' == $field || 'billing_address_2' == $field ) {
1516 $field_name = 'Street address line 2';
1517 }
1518
1519 if ( isset( $field_data['width'] ) ) {
1520 $width = $field_data['width'];
1521 } else {
1522 $width = get_post_meta( $post_id, 'wcf-field-width_' . $field, true );
1523 if ( ! $width ) {
1524 $width = $this->get_default_checkout_field_width( $field );
1525 }
1526 }
1527
1528 if ( isset( $field_data['enabled'] ) ) {
1529 $is_enabled = true === wc_string_to_bool( $field_data['enabled'] ) ? 'yes' : 'no';
1530 } else {
1531 $is_enabled = get_post_meta( $post_id, 'wcf-' . $field, true );
1532
1533 if ( '' === $is_enabled ) {
1534 $is_enabled = 'yes';
1535 }
1536 }
1537
1538 $field_args = array(
1539 'type' => ( isset( $field_data['type'] ) && ! empty( $field_data['type'] ) ) ? $field_data['type'] : '',
1540 'label' => $field_name,
1541 'key' => $field,
1542 'name' => 'wcf-' . $field,
1543 'placeholder' => isset( $field_data['placeholder'] ) ? $field_data['placeholder'] : '',
1544 'width' => $width,
1545 'enabled' => $is_enabled,
1546 'after' => 'Enable',
1547 'custom' => isset( $field_data['custom'] ) ? $field_data['custom'] : false,
1548 'custom_attributes' => isset( $field_data['custom_attributes'] ) ? wc_clean( $field_data['custom_attributes'] ) : array(),
1549 'section' => $type,
1550 'default' => isset( $field_data['default'] ) ? $field_data['default'] : '',
1551 'min' => isset( $field_data['min'] ) ? $field_data['min'] : '',
1552 'max' => isset( $field_data['max'] ) ? $field_data['max'] : '',
1553 'show_in_email' => ( isset( $field_data['show_in_email'] ) && wc_string_to_bool( $field_data['show_in_email'] ) ) ? 'yes' : 'no',
1554 'required' => ( isset( $field_data['required'] ) && wc_string_to_bool( $field_data['required'] ) ) ? 'yes' : 'no',
1555 'optimized' => ( isset( $field_data['optimized'] ) && wc_string_to_bool( $field_data['optimized'] ) ) ? 'yes' : 'no',
1556 'options' => ( isset( $field_data['options'] ) && ! empty( $field_data['options'] ) && is_array( $field_data['options'] ) ) ? implode( '|', $field_data['options'] ) : '',
1557 );
1558
1559 return $field_args;
1560 }
1561 }
1562
1563 /**
1564 * Kicking this off by calling 'get_instance()' method.
1565 */
1566 Cartflows_Checkout_Meta_Data::get_instance();
1567