PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.2.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.2.0
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.2.0, at modules/checkout/classes/class-cartflows-checkout-meta-data.php

1,597 lines 52.0 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 // Pro-only sections: register them here so their upgrade nudge shows; Pro replaces them with the real fields.
1119 if ( ! _is_cartflows_pro() ) {
1120 $settings['settings']['checkout-link'] = array(
1121 'title' => __( 'Checkout Link', 'cartflows' ),
1122 'slug' => 'checkout-link',
1123 'priority' => 30,
1124 'fields' => array(
1125 'checkout-link' => array(
1126 'type' => 'pro-notice',
1127 'feature' => 'Checkout Link',
1128 ),
1129 ),
1130 );
1131 // Checkout Expiry does not apply to the Store Checkout, so skip its nudge there.
1132 $flow_id = absint( get_post_meta( $step_id, 'wcf-flow-id', true ) );
1133 if ( ! ( $flow_id && absint( Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) ) === $flow_id ) ) {
1134 $settings['settings']['checkout-expiry'] = array(
1135 'title' => __( 'Checkout Expiry', 'cartflows' ),
1136 'slug' => 'checkout-expiry',
1137 'priority' => 40,
1138 'fields' => array(
1139 'checkout-expiry' => array(
1140 'type' => 'pro-notice',
1141 'feature' => 'Checkout Expiry',
1142 ),
1143 ),
1144 );
1145 }
1146 }
1147
1148 return apply_filters( 'cartflows_admin_checkout_settings_fields', $settings, $step_id );
1149 }
1150
1151 /**
1152 * Get data.
1153 *
1154 * @param int $step_id Post ID.
1155 */
1156 public function get_data( $step_id ) {
1157
1158 $optin_data = array();
1159
1160 // Stored data.
1161 $stored_meta = get_post_meta( $step_id );
1162
1163 // Default.
1164 $default_data = self::get_meta_option( $step_id );
1165
1166 // Set stored and override defaults.
1167 foreach ( $default_data as $key => $value ) {
1168 if ( array_key_exists( $key, $stored_meta ) ) {
1169 $optin_data[ $key ] = ( isset( $stored_meta[ $key ][0] ) ) ? maybe_unserialize( $stored_meta[ $key ][0] ) : '';
1170 } else {
1171 $optin_data[ $key ] = ( isset( $default_data[ $key ]['default'] ) ) ? $default_data[ $key ]['default'] : '';
1172 }
1173 }
1174
1175 return $optin_data;
1176 }
1177
1178 /**
1179 * Get meta.
1180 *
1181 * @param int $post_id Post ID.
1182 */
1183 public static function get_meta_option( $post_id ) {
1184
1185 $meta_option = wcf()->options->get_checkout_fields( $post_id );
1186
1187 return $meta_option;
1188 }
1189
1190 /**
1191 * Get name.
1192 *
1193 * @param int $id Product ID.
1194 */
1195 public static function get_name( $id ) {
1196
1197 $product_object = wc_get_product( $id );
1198
1199 $formatted_name = '';
1200
1201 if ( is_object( $product_object ) ) {
1202 $formatted_name = rawurldecode( $product_object->get_formatted_name() );
1203 }
1204 return $formatted_name;
1205 }
1206
1207 /**
1208 * Add custom meta fields
1209 *
1210 * @param int $post_id post id.
1211 */
1212 public function custom_fields_data( $post_id ) {
1213
1214 $billing_fields = $this->get_field_settings( $post_id, 'billing', '' );
1215 $shipping_fields = $this->get_field_settings( $post_id, 'shipping', '' );
1216
1217 $options = $this->get_data( $post_id );
1218
1219 $custom_fields = array(
1220 'extra_fields' => array(
1221 'title' => __( 'Form Settings', 'cartflows' ),
1222 'priority' => 10,
1223 'fields' => array(
1224 'enable-coupon-field' => array(
1225 'type' => 'toggle',
1226 'label' => __( 'Enable Coupon Field', 'cartflows' ),
1227 'name' => 'wcf-show-coupon-field',
1228 'is_fullwidth' => true,
1229 ),
1230 'collapse-coupon-field' => array(
1231 'type' => 'toggle',
1232 'label' => __( 'Collapsible Coupon Field', 'cartflows' ),
1233 'name' => 'wcf-optimize-coupon-field',
1234 'child_class' => 'wcf-cfe-child',
1235 'is_fullwidth' => true,
1236 'conditions' => array(
1237 'fields' => array(
1238 array(
1239 'name' => 'wcf-show-coupon-field',
1240 'operator' => '===',
1241 'value' => 'yes',
1242 ),
1243 ),
1244 ),
1245 ),
1246 'enable-additional-field' => array(
1247 'type' => 'toggle',
1248 'label' => __( 'Enable Additional Field', 'cartflows' ),
1249 'name' => 'wcf-checkout-additional-fields',
1250 'is_fullwidth' => true,
1251 ),
1252 'collapse-additional-field' => array(
1253 'type' => 'toggle',
1254 'label' => __( 'Collapsible Additional Field', 'cartflows' ),
1255 'name' => 'wcf-optimize-order-note-field',
1256 'child_class' => 'wcf-cfe-child',
1257 'is_fullwidth' => true,
1258 'conditions' => array(
1259 'fields' => array(
1260 array(
1261 'name' => 'wcf-checkout-additional-fields',
1262 'operator' => '===',
1263 'value' => 'yes',
1264 ),
1265 ),
1266 ),
1267 ),
1268 'shipping-field' => array(
1269 'type' => 'toggle',
1270 'label' => __( 'Enable Ship To Different Address', 'cartflows' ),
1271 'name' => 'wcf-shipto-diff-addr-fields',
1272 'is_fullwidth' => true,
1273 ),
1274
1275 'wcf-google-autoaddress' => array(
1276 'type' => 'toggle',
1277 'label' => __( 'Enable Google Address Autocomplete', 'cartflows' ),
1278 'name' => 'wcf-google-autoaddress',
1279 /* translators: %1$s: link html start, %2$s: link html end*/
1280 'desc' => __( 'Before enabling this option, make sure that you have added API key in Google Address Autocomplete Settings.', 'cartflows' ),
1281 'is_fullwidth' => true,
1282 ),
1283 'wcf-no-shipping-method-message-toggle' => array(
1284 'type' => 'toggle',
1285 'label' => __( 'Enable Custom Shipping Message', 'cartflows' ),
1286 'name' => 'wcf-custom-no-shipping-method-message-toggle',
1287 'value' => $options['wcf-custom-no-shipping-method-message-toggle'],
1288 'is_fullwidth' => true,
1289 'tooltip' => __( 'Turn this on to show a custom message when no shipping options are available at checkout.', 'cartflows' ),
1290 ),
1291 'wcf-no-shipping-method-message' => array(
1292 'type' => 'textarea',
1293 'label' => __( 'Shipping Message', 'cartflows' ),
1294 'name' => 'wcf-no-shipping-method-message',
1295 'value' => $options['wcf-no-shipping-method-message'],
1296 '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' ),
1297 'tooltip' => __( 'This message will be displayed when no shipping method is available.', 'cartflows' ),
1298 'rows' => 2,
1299 'cols' => 38,
1300 'display_align' => 'vertical',
1301 'conditions' => array(
1302 'fields' => array(
1303 array(
1304 'name' => 'wcf-custom-no-shipping-method-message-toggle',
1305 'operator' => '===',
1306 'value' => 'yes',
1307 ),
1308 ),
1309 ),
1310 ),
1311 'order-review-summary-position' => array(
1312 'type' => 'select',
1313 'name' => 'wcf-order-review-summary-position',
1314 'label' => __( 'Order Summary Position', 'cartflows' ),
1315 'display_align' => 'vertical',
1316 'value' => $options['wcf-order-review-summary-position'],
1317 'tooltip' => __( 'Choose this option to adjust where the order summary appears on mobile devices.', 'cartflows' ),
1318 'options' => array(
1319 array(
1320 'value' => 'top',
1321 'label' => __( 'Top', 'cartflows' ),
1322 ),
1323 array(
1324 'value' => 'bottom',
1325 'label' => __( 'Bottom', 'cartflows' ),
1326 ),
1327 ),
1328 ),
1329 ),
1330 ),
1331 'billing_fields' => array(
1332 'fields' => $billing_fields,
1333 ),
1334 'shipping_fields' => array(
1335 'fields' => $shipping_fields,
1336 ),
1337 // Checkout Fields.
1338 'checkout_settings' => array(
1339 'title' => __( 'Form Headings', 'cartflows' ),
1340 'slug' => 'checkout_setting',
1341 'priority' => 20,
1342 'fields' => array(
1343
1344 'wcf-billing-details-text' => array(
1345 'type' => 'text',
1346 'label' => __( 'Billing Details', 'cartflows' ),
1347 'name' => 'wcf-checkout-billing-details-text',
1348 'placeholder' => __( 'Billing details', 'cartflows' ),
1349 'display_align' => 'vertical',
1350 ),
1351 'wcf-shipping-details-text' => array(
1352 'type' => 'text',
1353 'label' => __( 'Shipping Details', 'cartflows' ),
1354 'name' => 'wcf-checkout-shipping-details-text',
1355 'placeholder' => __( 'Ship to a different address?', 'cartflows' ),
1356 'display_align' => 'vertical',
1357 ),
1358 'wcf-your-order-text' => array(
1359 'type' => 'text',
1360 'label' => __( 'Your Order', 'cartflows' ),
1361 'name' => 'wcf-checkout-your-order-text',
1362 'placeholder' => __( 'Your order', 'cartflows' ),
1363 'display_align' => 'vertical',
1364 ),
1365 'wcf-customer-info-text' => array(
1366 'type' => 'text',
1367 'label' => __( 'Customer Information', 'cartflows' ),
1368 'name' => 'wcf-checkout-customer-info-text',
1369 'placeholder' => __( 'Customer information', 'cartflows' ),
1370 'tooltip' => __( 'This heading will only appear when you use the Modern Checkout style.', 'cartflows' ),
1371 'display_align' => 'vertical',
1372 ),
1373 'wcf-payment-text' => array(
1374 'type' => 'text',
1375 'label' => __( 'Payment', 'cartflows' ),
1376 'name' => 'wcf-checkout-payment-text',
1377 'placeholder' => __( 'Payment', 'cartflows' ),
1378 'tooltip' => __( 'This heading will only appear when you use the Modern Checkout style.', 'cartflows' ),
1379 'display_align' => 'vertical',
1380 ),
1381 'wcf-enable-validation-text' => array(
1382 'type' => 'toggle',
1383 'label' => __( 'Enable Field Validation Error Message', 'cartflows' ),
1384 'name' => 'wcf-enable-checkout-field-validation-text',
1385 'value' => $options['wcf-enable-checkout-field-validation-text'],
1386 'tooltip' => __( 'This message will appear next to the field name to show an error if something goes wrong.', 'cartflows' ),
1387 'is_fullwidth' => true,
1388 ),
1389 'wcf-field-validation-text' => array(
1390 'type' => 'text',
1391 'label' => __( 'Validation Error Message', 'cartflows' ),
1392 'name' => 'wcf-checkout-field-validation-text',
1393 'placeholder' => __( 'is required', 'cartflows' ),
1394 'display_align' => 'vertical',
1395 'conditions' => array(
1396 'fields' => array(
1397 array(
1398 'name' => 'wcf-enable-checkout-field-validation-text',
1399 'operator' => '===',
1400 'value' => 'yes',
1401 ),
1402 ),
1403 ),
1404 ),
1405 ),
1406 ),
1407 // Checkout Fields.
1408 'button_settings' => array(
1409 'title' => __( 'Place Order Button', 'cartflows' ),
1410 'slug' => 'button_settings',
1411 'priority' => 20,
1412 'fields' => array(
1413 'wcf-place-order-button-text' => array(
1414 'type' => 'text',
1415 'label' => __( 'Button Text', 'cartflows' ),
1416 'name' => 'wcf-checkout-place-order-button-text',
1417 'value' => $options['wcf-checkout-place-order-button-text'],
1418 'placeholder' => __( 'Place Order', 'cartflows' ),
1419 'tooltip' => __( 'Customizes the text on the \'Place Order\' button during checkout, allowing you to make it more relevant to your customers.', 'cartflows' ),
1420 'display_align' => 'vertical',
1421 ),
1422 'wcf-place-order-button-icon' => array(
1423 'type' => 'toggle',
1424 'label' => __( 'Enable Lock Icon', 'cartflows' ),
1425 'name' => 'wcf-checkout-place-order-button-lock',
1426 'value' => $options['wcf-checkout-place-order-button-lock'],
1427 'tooltip' => __( 'Enabling this will add a lock icon to the \'Place Order\' button on the checkout page, indicating secure payment processing.', 'cartflows' ),
1428 'is_fullwidth' => true,
1429 ),
1430
1431 'wcf-place-order-price-display' => array(
1432 'type' => 'toggle',
1433 'label' => __( 'Enable Price Display', 'cartflows' ),
1434 'name' => 'wcf-checkout-place-order-button-price-display',
1435 'value' => $options['wcf-checkout-place-order-button-price-display'],
1436 'tooltip' => __( 'This will display the total amount in the cart when you click the \'Place Order\' button.', 'cartflows' ),
1437 'is_fullwidth' => true,
1438 ),
1439 ),
1440 ),
1441 );
1442
1443 $custom_fields = apply_filters( 'cartflows_admin_checkout_editor_settings', $custom_fields );
1444
1445 return $custom_fields;
1446 }
1447
1448 /**
1449 * Add custom meta fields
1450 *
1451 * @param string $post_id post id.
1452 * @param array $fields fields.
1453 * @param array $new_fields new fields.
1454 */
1455 public function get_field_settings( $post_id, $fields, $new_fields ) {
1456
1457 if ( 'billing' === $fields ) {
1458 $get_ordered_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
1459 } else {
1460 $get_ordered_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
1461 }
1462
1463 if ( isset( $get_ordered_fields ) && ! empty( $get_ordered_fields ) ) {
1464 $data_array = $get_ordered_fields;
1465
1466 } else {
1467 $data_array = Cartflows_Helper::get_checkout_fields( $fields, $post_id );
1468 }
1469
1470 if ( isset( $new_fields ) && ! empty( $new_fields ) && is_array( $new_fields ) ) {
1471 $data_array = $new_fields;
1472 }
1473 $field_args = array();
1474
1475 foreach ( $data_array as $key => $value ) {
1476
1477 $field_args = $this->prepare_field_arguments( $key, $value, $post_id, $fields );
1478
1479 foreach ( $field_args as $arg_key => $arg_val ) {
1480
1481 if ( ! in_array( $arg_key, $value, true ) ) {
1482
1483 $data_array[ $key ][ $arg_key ] = $arg_val;
1484 }
1485 }
1486
1487 $data_array[ $key ] = Cartflows_Helper::get_instance()->prepare_custom_field_settings( $data_array[ $key ], $key, $field_args, $fields, 'checkout' );
1488 }
1489
1490 return $data_array;
1491 }
1492
1493 /**
1494 * Fetch default width of checkout fields by key.
1495 *
1496 * @param string $checkout_field_key field key.
1497 * @return int
1498 */
1499 public function get_default_checkout_field_width( $checkout_field_key ) {
1500
1501 $default_width = 100;
1502 switch ( $checkout_field_key ) {
1503 case 'billing_first_name':
1504 case 'billing_last_name':
1505 case 'billing_address_1':
1506 case 'billing_address_2':
1507 case 'shipping_first_name':
1508 case 'shipping_last_name':
1509 case 'shipping_address_1':
1510 case 'shipping_address_2':
1511 $default_width = 50;
1512 break;
1513
1514 case 'billing_city':
1515 case 'billing_state':
1516 case 'billing_postcode':
1517 case 'shipping_city':
1518 case 'shipping_state':
1519 case 'shipping_postcode':
1520 $default_width = 33;
1521 break;
1522
1523 default:
1524 $default_width = 100;
1525 break;
1526 }
1527
1528 return $default_width;
1529 }
1530
1531
1532 /**
1533 * Prepare HTML data for billing and shipping fields.
1534 *
1535 * @param string $field checkout field key.
1536 * @param array $field_data checkout field object.
1537 * @param integer $post_id chcekout post id.
1538 * @param string $type checkout field type.
1539 * @return array
1540 */
1541 public function prepare_field_arguments( $field, $field_data, $post_id, $type ) {
1542
1543 if ( isset( $field_data['label'] ) ) {
1544 $field_name = $field_data['label'];
1545 } elseif ( 'shipping_address_2' == $field || 'billing_address_2' == $field ) {
1546 $field_name = 'Street address line 2';
1547 }
1548
1549 if ( isset( $field_data['width'] ) ) {
1550 $width = $field_data['width'];
1551 } else {
1552 $width = get_post_meta( $post_id, 'wcf-field-width_' . $field, true );
1553 if ( ! $width ) {
1554 $width = $this->get_default_checkout_field_width( $field );
1555 }
1556 }
1557
1558 if ( isset( $field_data['enabled'] ) ) {
1559 $is_enabled = true === wc_string_to_bool( $field_data['enabled'] ) ? 'yes' : 'no';
1560 } else {
1561 $is_enabled = get_post_meta( $post_id, 'wcf-' . $field, true );
1562
1563 if ( '' === $is_enabled ) {
1564 $is_enabled = 'yes';
1565 }
1566 }
1567
1568 $field_args = array(
1569 'type' => ( isset( $field_data['type'] ) && ! empty( $field_data['type'] ) ) ? $field_data['type'] : '',
1570 'label' => $field_name,
1571 'key' => $field,
1572 'name' => 'wcf-' . $field,
1573 'placeholder' => isset( $field_data['placeholder'] ) ? $field_data['placeholder'] : '',
1574 'width' => $width,
1575 'enabled' => $is_enabled,
1576 'after' => 'Enable',
1577 'custom' => isset( $field_data['custom'] ) ? $field_data['custom'] : false,
1578 'custom_attributes' => isset( $field_data['custom_attributes'] ) ? wc_clean( $field_data['custom_attributes'] ) : array(),
1579 'section' => $type,
1580 'default' => isset( $field_data['default'] ) ? $field_data['default'] : '',
1581 'min' => isset( $field_data['min'] ) ? $field_data['min'] : '',
1582 'max' => isset( $field_data['max'] ) ? $field_data['max'] : '',
1583 'show_in_email' => ( isset( $field_data['show_in_email'] ) && wc_string_to_bool( $field_data['show_in_email'] ) ) ? 'yes' : 'no',
1584 'required' => ( isset( $field_data['required'] ) && wc_string_to_bool( $field_data['required'] ) ) ? 'yes' : 'no',
1585 'optimized' => ( isset( $field_data['optimized'] ) && wc_string_to_bool( $field_data['optimized'] ) ) ? 'yes' : 'no',
1586 'options' => ( isset( $field_data['options'] ) && ! empty( $field_data['options'] ) && is_array( $field_data['options'] ) ) ? implode( '|', $field_data['options'] ) : '',
1587 );
1588
1589 return $field_args;
1590 }
1591 }
1592
1593 /**
1594 * Kicking this off by calling 'get_instance()' method.
1595 */
1596 Cartflows_Checkout_Meta_Data::get_instance();
1597