PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.17
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.17
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 / classes / class-cartflows-default-meta.php

class-cartflows-default-meta.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.1.17, at classes/class-cartflows-default-meta.php

927 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cartflow default options.
4 *
5 * @package Cartflows
6 */
7
8 /**
9 * Initialization
10 *
11 * @since 1.0.0
12 */
13 class Cartflows_Default_Meta {
14
15
16 /**
17 * Member Variable
18 *
19 * @var instance
20 */
21 private static $instance;
22
23 /**
24 * Member Variable
25 *
26 * @var checkout_fields
27 */
28 private static $checkout_fields = null;
29
30 /**
31 * Member Variable
32 *
33 * @var checkout_fields
34 */
35 private static $thankyou_fields = null;
36
37 /**
38 * Member Variable
39 *
40 * @var flow_fields
41 */
42 private static $flow_fields = null;
43
44 /**
45 * Member Variable
46 *
47 * @var landing_fields
48 */
49 private static $landing_fields = null;
50
51 /**
52 * Initiator
53 */
54 public static function get_instance() {
55 if ( ! isset( self::$instance ) ) {
56 self::$instance = new self;
57 }
58 return self::$instance;
59 }
60
61 /**
62 * Constructor
63 */
64 public function __construct() {
65
66 }
67
68 /**
69 * Checkout Default fields.
70 *
71 * @param int $post_id post id.
72 * @return array
73 */
74 function get_checkout_fields( $post_id ) {
75
76 if ( null === self::$checkout_fields ) {
77
78 self::$checkout_fields = array(
79 'wcf-field-google-font-url' => array(
80 'default' => '',
81 'sanitize' => 'FILTER_DEFAULT',
82 ),
83 'wcf-checkout-products' => array(
84 'default' => array(),
85 'sanitize' => 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS',
86 ),
87 'wcf-checkout-layout' => array(
88 'default' => 'two-column',
89 'sanitize' => 'FILTER_DEFAULT',
90 ),
91 'wcf-input-font-family' => array(
92 'default' => '',
93 'sanitize' => 'FILTER_DEFAULT',
94 ),
95 'wcf-input-font-weight' => array(
96 'default' => '',
97 'sanitize' => 'FILTER_DEFAULT',
98 ),
99 'wcf-heading-font-family' => array(
100 'default' => '',
101 'sanitize' => 'FILTER_DEFAULT',
102 ),
103 'wcf-heading-font-weight' => array(
104 'default' => '',
105 'sanitize' => 'FILTER_DEFAULT',
106 ),
107 'wcf-base-font-family' => array(
108 'default' => '',
109 'sanitize' => 'FILTER_DEFAULT',
110 ),
111 'wcf-advance-options-fields' => array(
112 'default' => '',
113 'sanitize' => 'FILTER_DEFAULT',
114 ),
115 'wcf-base-font-weight' => array(
116 'default' => '',
117 'sanitize' => 'FILTER_DEFAULT',
118 ),
119 'wcf-button-font-family' => array(
120 'default' => '',
121 'sanitize' => 'FILTER_DEFAULT',
122 ),
123 'wcf-button-font-weight' => array(
124 'default' => '',
125 'sanitize' => 'FILTER_DEFAULT',
126 ),
127 'wcf-primary-color' => array(
128 'default' => '',
129 'sanitize' => 'FILTER_DEFAULT',
130 ),
131 'wcf-heading-color' => array(
132 'default' => '',
133 'sanitize' => 'FILTER_DEFAULT',
134 ),
135 'wcf-section-bg-color' => array(
136 'default' => '',
137 'sanitize' => 'FILTER_DEFAULT',
138 ),
139 'wcf-hl-bg-color' => array(
140 'default' => '',
141 'sanitize' => 'FILTER_DEFAULT',
142 ),
143 'wcf-field-tb-padding' => array(
144 'default' => '',
145 'sanitize' => 'FILTER_DEFAULT',
146 ),
147 'wcf-field-lr-padding' => array(
148 'default' => '',
149 'sanitize' => 'FILTER_DEFAULT',
150 ),
151 'wcf-fields-skins' => array(
152 'default' => '',
153 'sanitize' => 'FILTER_DEFAULT',
154 ),
155 'wcf-input-field-size' => array(
156 'default' => '33px',
157 'sanitize' => 'FILTER_DEFAULT',
158 ),
159 'wcf-field-color' => array(
160 'default' => '',
161 'sanitize' => 'FILTER_DEFAULT',
162 ),
163 'wcf-field-bg-color' => array(
164 'default' => '',
165 'sanitize' => 'FILTER_DEFAULT',
166 ),
167 'wcf-field-border-color' => array(
168 'default' => '',
169 'sanitize' => 'FILTER_DEFAULT',
170 ),
171 'wcf-box-border-color' => array(
172 'default' => '',
173 'sanitize' => 'FILTER_DEFAULT',
174 ),
175 'wcf-field-label-color' => array(
176 'default' => '',
177 'sanitize' => 'FILTER_DEFAULT',
178 ),
179 'wcf-submit-tb-padding' => array(
180 'default' => '',
181 'sanitize' => 'FILTER_DEFAULT',
182 ),
183 'wcf-submit-lr-padding' => array(
184 'default' => '',
185 'sanitize' => 'FILTER_DEFAULT',
186 ),
187 'wcf-input-button-size' => array(
188 'default' => '33px',
189 'sanitize' => 'FILTER_DEFAULT',
190 ),
191 'wcf-submit-color' => array(
192 'default' => '',
193 'sanitize' => 'FILTER_DEFAULT',
194 ),
195 'wcf-submit-hover-color' => array(
196 'default' => '',
197 'sanitize' => 'FILTER_DEFAULT',
198 ),
199 'wcf-submit-bg-color' => array(
200 'default' => '',
201 'sanitize' => 'FILTER_DEFAULT',
202 ),
203 'wcf-submit-bg-hover-color' => array(
204 'default' => '',
205 'sanitize' => 'FILTER_DEFAULT',
206 ),
207 'wcf-submit-border-color' => array(
208 'default' => '',
209 'sanitize' => 'FILTER_DEFAULT',
210 ),
211 'wcf-submit-border-hover-color' => array(
212 'default' => '',
213 'sanitize' => 'FILTER_DEFAULT',
214 ),
215 'wcf-active-tab' => array(
216 'default' => '',
217 'sanitize' => 'FILTER_DEFAULT',
218 ),
219 'wcf-header-logo-image' => array(
220 'default' => '',
221 'sanitize' => 'FILTER_DEFAULT',
222 ),
223 'wcf-header-logo-width' => array(
224 'default' => '',
225 'sanitize' => 'FILTER_DEFAULT',
226 ),
227 'wcf-custom-script' => array(
228 'default' => '',
229 'sanitize' => 'FILTER_DEFAULT',
230 ),
231 );
232
233 self::$checkout_fields = apply_filters( 'cartflows_checkout_meta_options', self::$checkout_fields, $post_id );
234 }
235
236 return self::$checkout_fields;
237 }
238
239 /**
240 * Save Checkout Meta fields.
241 *
242 * @param int $post_id post id.
243 * @return void
244 */
245 function save_checkout_fields( $post_id ) {
246
247 $post_meta = $this->get_checkout_fields( $post_id );
248
249 $this->save_meta_fields( $post_id, $post_meta );
250 }
251
252 /**
253 * Save Landing Meta fields.
254 *
255 * @param int $post_id post id.
256 * @return void
257 */
258 function save_landing_fields( $post_id ) {
259
260 $post_meta = $this->get_landing_fields( $post_id );
261
262 $this->save_meta_fields( $post_id, $post_meta );
263 }
264
265 /**
266 * Save ThankYou Meta fields.
267 *
268 * @param int $post_id post id.
269 * @return void
270 */
271 function save_thankyou_fields( $post_id ) {
272
273 $post_meta = $this->get_thankyou_fields( $post_id );
274
275 $this->save_meta_fields( $post_id, $post_meta );
276 }
277
278 /**
279 * Flow Default fields.
280 *
281 * @param int $post_id post id.
282 * @return array
283 */
284 function get_flow_fields( $post_id ) {
285
286 if ( null === self::$flow_fields ) {
287
288 self::$flow_fields = array(
289 'wcf-steps' => array(
290 'default' => array(),
291 'sanitize' => 'FILTER_DEFAULT',
292 ),
293
294 'wcf-testing' => array(
295 'default' => 'yes',
296 'sanitize' => 'FILTER_DEFAULT',
297 ),
298 );
299 }
300
301 return apply_filters( 'cartflows_flow_meta_options', self::$flow_fields );
302 }
303
304 /**
305 * Save Flow Meta fields.
306 *
307 * @param int $post_id post id.
308 * @return void
309 */
310 function save_flow_fields( $post_id ) {
311
312 $post_meta = $this->get_flow_fields( $post_id );
313
314 if ( isset( $post_meta['wcf-steps'] ) ) {
315 unset( $post_meta['wcf-steps'] );
316 }
317
318 $this->save_meta_fields( $post_id, $post_meta );
319 }
320
321 /**
322 * Save Meta fields - Common Function.
323 *
324 * @param int $post_id post id.
325 * @param array $post_meta options to store.
326 * @return void
327 */
328 function save_meta_fields( $post_id, $post_meta ) {
329
330 if ( ! ( $post_id && is_array( $post_meta ) ) ) {
331
332 return;
333 }
334
335 foreach ( $post_meta as $key => $data ) {
336
337 $meta_value = false;
338
339 // Sanitize values.
340 $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
341
342 switch ( $sanitize_filter ) {
343
344 case 'FILTER_SANITIZE_STRING':
345 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
346 break;
347
348 case 'FILTER_SANITIZE_URL':
349 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
350 break;
351
352 case 'FILTER_SANITIZE_NUMBER_INT':
353 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
354 break;
355
356 case 'FILTER_CARTFLOWS_ARRAY':
357 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
358 $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
359 }
360 break;
361
362 case 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS':
363 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
364
365 $i = 0;
366 $q = 0;
367
368 foreach ( $_POST[ $key ] as $p_index => $p_data ) {
369
370 foreach ( $p_data as $i_key => $i_value ) {
371
372 if ( is_array( $i_value ) ) {
373
374 foreach ( $i_value as $q_key => $q_value ) {
375
376 $meta_value[ $i ][ $i_key ][ $q ] = array_map( 'sanitize_text_field', $q_value );
377
378 $q++;
379 }
380 } else {
381 $meta_value[ $i ][ $i_key ] = sanitize_text_field( $i_value );
382 }
383 }
384
385 $i++;
386 }
387 }
388 break;
389 case 'FILTER_CARTFLOWS_CHECKOUT_FIELDS':
390 $count = 10;
391 $ordered_fields = array();
392 $billing_fields = array();
393
394 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
395 $post_data = $_POST[ $key ];
396
397 if ( 'wcf_field_order_billing' == $key ) {
398
399 $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
400
401 foreach ( $post_data as $index => $value ) {
402
403 if ( isset( $billing_fields[ $value ] ) ) {
404 $ordered_fields[ $value ] = $billing_fields[ $value ];
405 $ordered_fields[ $value ]['priority'] = $count;
406 $count += 10;
407 }
408 }
409
410 $meta_value = $ordered_fields;
411 }
412
413 if ( 'wcf_field_order_shipping' == $key ) {
414
415 $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
416 foreach ( $post_data as $index => $value ) {
417
418 if ( isset( $shipping_fields[ $value ] ) ) {
419 $ordered_fields[ $value ] = $shipping_fields[ $value ];
420 $ordered_fields[ $value ]['priority'] = $count;
421 $count += 10;
422 }
423 }
424 $meta_value = $ordered_fields;
425 }
426
427 if ( 'wcf_label_text_field_billing' == $key ) {
428
429 $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
430
431 if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
432 echo 'con 1';
433 $billing_fields = $get_ordered_billing_fields;
434 } else {
435 echo 'con 2';
436 $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
437 }
438
439 foreach ( $post_data as $index => $value ) {
440
441 if ( isset( $billing_fields[ $index ] ) ) {
442 $ordered_fields[ $index ] = $billing_fields[ $index ];
443 $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
444 }
445 }
446 $key = 'wcf_field_order_billing';
447 $meta_value = $ordered_fields;
448 }
449
450 if ( 'wcf_label_text_field_shipping' == $key ) {
451
452 $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
453
454 if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
455 $shipping_fields = $get_ordered_shipping_fields;
456 } else {
457 $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
458 }
459
460 foreach ( $post_data as $index => $value ) {
461
462 if ( isset( $shipping_fields[ $index ] ) ) {
463 $ordered_fields[ $index ] = $shipping_fields[ $index ];
464 $ordered_fields[ $index ]['label'] = wp_kses_post( trim( stripslashes( $value ) ) );
465 }
466 }
467 $key = 'wcf_field_order_shipping';
468 $meta_value = $ordered_fields;
469 }
470
471 if ( 'wcf_label_placeholder_field_billing' == $key ) {
472 $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
473
474 if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
475 $billing_fields = $get_ordered_billing_fields;
476 } else {
477 $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
478 }
479 foreach ( $post_data as $index => $value ) {
480
481 if ( isset( $billing_fields[ $index ] ) ) {
482 $ordered_fields[ $index ] = $billing_fields[ $index ];
483 $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
484 }
485 }
486
487 $key = 'wcf_field_order_billing';
488 $meta_value = $ordered_fields;
489 }
490
491 if ( 'wcf_label_placeholder_field_shipping' == $key ) {
492 $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
493
494 if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
495 $shipping_fields = $get_ordered_shipping_fields;
496 } else {
497 $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
498 }
499
500 foreach ( $post_data as $index => $value ) {
501
502 if ( isset( $shipping_fields[ $index ] ) ) {
503 $ordered_fields[ $index ] = $shipping_fields[ $index ];
504 $ordered_fields[ $index ]['placeholder'] = wc_clean( stripslashes( $value ) );
505 }
506 }
507
508 $key = 'wcf_field_order_shipping';
509 $meta_value = $ordered_fields;
510
511 }
512
513 if ( 'wcf_label_default_field_billing' == $key ) {
514
515 $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
516
517 if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
518 $billing_fields = $get_ordered_billing_fields;
519 } else {
520 $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
521 }
522
523 foreach ( $post_data as $index => $value ) {
524
525 if ( isset( $billing_fields[ $index ] ) ) {
526 $ordered_fields[ $index ] = $billing_fields[ $index ];
527 $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
528 }
529 }
530
531 $key = 'wcf_field_order_billing';
532 $meta_value = $ordered_fields;
533 }
534
535 if ( 'wcf_label_default_field_shipping' == $key ) {
536
537 $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
538
539 if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
540 $shipping_fields = $get_ordered_shipping_fields;
541 } else {
542 $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
543 }
544
545 foreach ( $post_data as $index => $value ) {
546
547 if ( isset( $shipping_fields[ $index ] ) ) {
548 $ordered_fields[ $index ] = $shipping_fields[ $index ];
549 $ordered_fields[ $index ]['default'] = wp_kses_post( trim( stripslashes( $value ) ) );
550 }
551 }
552
553 $key = 'wcf_field_order_shipping';
554 $meta_value = $ordered_fields;
555 }
556
557 if ( 'wcf_is_required_field_billing' == $key ) {
558
559 $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
560
561 if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
562 $billing_fields = $get_ordered_billing_fields;
563 } else {
564 $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
565 }
566
567 foreach ( $post_data as $index => $value ) {
568
569 if ( isset( $billing_fields[ $index ] ) ) {
570 $ordered_fields[ $index ] = $billing_fields[ $index ];
571 if ( 'yes' == $value ) {
572
573 $ordered_fields[ $index ]['required'] = true;
574 } else {
575 $ordered_fields[ $index ]['required'] = false;
576 }
577 }
578 }
579
580 $key = 'wcf_field_order_billing';
581 $meta_value = $ordered_fields;
582 }
583
584 if ( 'wcf_is_required_field_shipping' == $key ) {
585
586 $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
587
588 if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
589 $shipping_fields = $get_ordered_shipping_fields;
590 } else {
591 $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
592 }
593
594 foreach ( $post_data as $index => $value ) {
595
596 if ( isset( $shipping_fields[ $index ] ) ) {
597 $ordered_fields[ $index ] = $shipping_fields[ $index ];
598
599 if ( 'yes' == $value ) {
600
601 $ordered_fields[ $index ]['required'] = true;
602 } else {
603 $ordered_fields[ $index ]['required'] = false;
604 }
605 }
606 }
607
608 $key = 'wcf_field_order_shipping';
609 $meta_value = $ordered_fields;
610 }
611
612 if ( 'wcf_select_option_field_billing' == $key ) {
613
614 $get_ordered_billing_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_billing' );
615
616 if ( isset( $get_ordered_billing_fields ) && ! empty( $get_ordered_billing_fields ) ) {
617 $billing_fields = $get_ordered_billing_fields;
618 } else {
619 $billing_fields = Cartflows_Helper::get_checkout_fields( 'billing', $post_id );
620 }
621
622 foreach ( $post_data as $index => $value ) {
623
624 $options = explode( ',', $value );
625
626 if ( isset( $billing_fields[ $index ] ) ) {
627 $ordered_fields[ $index ] = $billing_fields[ $index ];
628
629 $ordered_fields[ $index ]['options'] = array();
630
631 foreach ( $options as $key => $option ) {
632
633 $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
634 }
635 }
636 }
637
638 $key = 'wcf_field_order_billing';
639 $meta_value = $ordered_fields;
640 }
641
642 if ( 'wcf_select_option_field_shipping' == $key ) {
643
644 $get_ordered_shipping_fields = wcf()->options->get_checkout_meta_value( $post_id, 'wcf_field_order_shipping' );
645
646 if ( isset( $get_ordered_shipping_fields ) && ! empty( $get_ordered_shipping_fields ) ) {
647 $shipping_fields = $get_ordered_shipping_fields;
648 } else {
649 $shipping_fields = Cartflows_Helper::get_checkout_fields( 'shipping', $post_id );
650 }
651
652 foreach ( $post_data as $index => $value ) {
653
654 $options = explode( ',', $value );
655
656 if ( isset( $shipping_fields[ $index ] ) ) {
657
658 $ordered_fields[ $index ] = $shipping_fields[ $index ];
659
660 $ordered_fields[ $index ]['options'] = array();
661
662 foreach ( $options as $key => $option ) {
663
664 $ordered_fields[ $index ]['options'][ $option ] = trim( stripslashes( $option ) );
665 }
666 }
667 }
668
669 $key = 'wcf_field_order_shipping';
670 $meta_value = $ordered_fields;
671 }
672 }
673 break;
674
675 default:
676 $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
677 break;
678 }
679
680 if ( false !== $meta_value ) {
681 update_post_meta( $post_id, $key, $meta_value );
682 } else {
683 delete_post_meta( $post_id, $key );
684 }
685 }
686 }
687
688 /**
689 * Get checkout meta.
690 *
691 * @param int $post_id post id.
692 * @param string $key options key.
693 * @param mix $default options default value.
694 * @return string
695 */
696 function get_flow_meta_value( $post_id, $key, $default = false ) {
697
698 $value = $this->get_save_meta( $post_id, $key );
699
700 if ( ! $value ) {
701
702 if ( $default ) {
703
704 $value = $default;
705 } else {
706
707 $fields = $this->get_flow_fields( $post_id );
708
709 if ( isset( $fields[ $key ]['default'] ) ) {
710
711 $value = $fields[ $key ]['default'];
712 }
713 }
714 }
715
716 return $value;
717 }
718
719 /**
720 * Get checkout meta.
721 *
722 * @param int $post_id post id.
723 * @param string $key options key.
724 * @param mix $default options default value.
725 * @return string
726 */
727 function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) {
728
729 $value = $this->get_save_meta( $post_id, $key );
730
731 if ( ! $value ) {
732
733 if ( false !== $default ) {
734
735 $value = $default;
736 } else {
737
738 $fields = $this->get_checkout_fields( $post_id );
739
740 if ( isset( $fields[ $key ]['default'] ) ) {
741
742 $value = $fields[ $key ]['default'];
743 }
744 }
745 }
746
747 return $value;
748 }
749
750 /**
751 * Get post meta.
752 *
753 * @param int $post_id post id.
754 * @param string $key options key.
755 * @return string
756 */
757 function get_save_meta( $post_id, $key ) {
758
759 $value = get_post_meta( $post_id, $key, true );
760
761 return $value;
762 }
763
764 /**
765 * Thank You Default fields.
766 *
767 * @param int $post_id post id.
768 * @return array
769 */
770 function get_thankyou_fields( $post_id ) {
771
772 if ( null === self::$thankyou_fields ) {
773
774 self::$thankyou_fields = array(
775 'wcf-field-google-font-url' => array(
776 'default' => '',
777 'sanitize' => 'FILTER_DEFAULT',
778 ),
779 'wcf-active-tab' => array(
780 'default' => '',
781 'sanitize' => 'FILTER_DEFAULT',
782 ),
783 'wcf-tq-text-color' => array(
784 'default' => '',
785 'sanitize' => 'FILTER_DEFAULT',
786 ),
787 'wcf-tq-font-family' => array(
788 'default' => '',
789 'sanitize' => 'FILTER_DEFAULT',
790 ),
791 'wcf-tq-heading-color' => array(
792 'default' => '',
793 'sanitize' => 'FILTER_DEFAULT',
794 ),
795 'wcf-tq-heading-font-family' => array(
796 'default' => '',
797 'sanitize' => 'FILTER_DEFAULT',
798 ),
799 'wcf-tq-heading-font-wt' => array(
800 'default' => '',
801 'sanitize' => 'FILTER_DEFAULT',
802 ),
803 'wcf-tq-container-width' => array(
804 'default' => '',
805 'sanitize' => 'FILTER_DEFAULT',
806 ),
807 'wcf-tq-section-bg-color' => array(
808 'default' => '',
809 'sanitize' => 'FILTER_DEFAULT',
810 ),
811 'wcf-tq-advance-options-fields' => array(
812 'default' => '',
813 'sanitize' => 'FILTER_DEFAULT',
814 ),
815 'wcf-show-overview-section' => array(
816 'default' => 'yes',
817 'sanitize' => 'FILTER_DEFAULT',
818 ),
819 'wcf-show-details-section' => array(
820 'default' => 'yes',
821 'sanitize' => 'FILTER_DEFAULT',
822 ),
823 'wcf-show-billing-section' => array(
824 'default' => 'yes',
825 'sanitize' => 'FILTER_DEFAULT',
826 ),
827 'wcf-show-shipping-section' => array(
828 'default' => 'yes',
829 'sanitize' => 'FILTER_DEFAULT',
830 ),
831 'wcf-custom-script' => array(
832 'default' => '',
833 'sanitize' => 'FILTER_DEFAULT',
834 ),
835 );
836
837 }
838
839 return apply_filters( 'cartflows_thankyou_meta_options', self::$thankyou_fields, $post_id );
840 }
841
842 /**
843 * Get Thank you section meta.
844 *
845 * @param int $post_id post id.
846 * @param string $key options key.
847 * @param mix $default options default value.
848 * @return string
849 */
850 function get_thankyou_meta_value( $post_id, $key, $default = false ) {
851
852 $value = $this->get_save_meta( $post_id, $key );
853
854 if ( ! $value ) {
855
856 if ( $default ) {
857
858 $value = $default;
859 } else {
860
861 $fields = $this->get_thankyou_fields( $post_id );
862
863 if ( isset( $fields[ $key ]['default'] ) ) {
864
865 $value = $fields[ $key ]['default'];
866 }
867 }
868 }
869
870 return $value;
871 }
872
873 /**
874 * Get Landing section meta.
875 *
876 * @param int $post_id post id.
877 * @param string $key options key.
878 * @param mix $default options default value.
879 * @return string
880 */
881 function get_landing_meta_value( $post_id, $key, $default = false ) {
882
883 $value = $this->get_save_meta( $post_id, $key );
884 if ( ! $value ) {
885
886 if ( $default ) {
887
888 $value = $default;
889 } else {
890
891 $fields = $this->get_landing_fields( $post_id );
892
893 if ( isset( $fields[ $key ]['default'] ) ) {
894 $value = $fields[ $key ]['default'];
895 }
896 }
897 }
898
899 return $value;
900 }
901
902 /**
903 * Thank You Default fields.
904 *
905 * @param int $post_id post id.
906 * @return array
907 */
908 function get_landing_fields( $post_id ) {
909
910 if ( null === self::$landing_fields ) {
911
912 self::$landing_fields = array(
913 'wcf-custom-script' => array(
914 'default' => '',
915 'sanitize' => 'FILTER_DEFAULT',
916 ),
917 );
918 }
919 return apply_filters( 'cartflows_landing_meta_options', self::$landing_fields, $post_id );
920 }
921 }
922
923 /**
924 * Kicking this off by calling 'get_instance()' method
925 */
926 Cartflows_Default_Meta::get_instance();
927