PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.19
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.19
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-meta-fields.php

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

1,483 lines 46.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreStart
3 /**
4 * Meta Fields.
5 *
6 * @package CartFlows
7 */
8
9 /**
10 * Class Cartflows_Meta_Fields.
11 */
12 class Cartflows_Meta_Fields {
13
14 /**
15 * Instance
16 *
17 * @var $instance
18 */
19 private static $instance;
20
21 /**
22 * Initiator
23 */
24 public static function get_instance() {
25 if ( ! isset( self::$instance ) ) {
26 self::$instance = new self;
27 }
28
29 return self::$instance;
30 }
31
32 /**
33 * Constructor
34 */
35 public function __construct() {
36
37 /* Add Scripts */
38 add_action( 'admin_enqueue_scripts', array( $this, 'admin_meta_scripts' ), 20 );
39
40 add_action( 'wp_ajax_wcf_json_search_coupons', array( $this, 'json_search_coupons' ) );
41
42 add_action( 'wp_ajax_wcf_add_checkout_custom_field', array( $this, 'add_checkout_custom_field' ) );
43
44 add_action( 'wp_ajax_wcf_pro_add_checkout_custom_field', array( $this, 'add_pro_checkout_custom_field' ) );
45
46 add_action( 'wp_ajax_wcf_delete_checkout_custom_field', array( $this, 'delete_checkout_custom_field' ) );
47
48 add_action( 'wp_ajax_wcf_json_search_pages', array( $this, 'json_search_pages' ) );
49
50 add_filter( 'cartflows_admin_js_localize', array( $this, 'localize_vars' ) );
51 }
52
53 public function admin_meta_scripts() {
54
55 global $pagenow;
56 global $post;
57
58 $screen = get_current_screen();
59
60 if (
61 ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) &&
62 wcf()->utils->is_step_post_type( $screen->post_type )
63 ) {
64
65 wp_enqueue_style( 'woocommerce_admin_styles' );
66
67 wp_enqueue_script( 'select2' );
68 wp_enqueue_script( 'wc-enhanced-select' );
69
70 wp_enqueue_script(
71 'wcf-admin-meta',
72 CARTFLOWS_URL . 'admin/meta-assets/js/admin-edit.js',
73 array( 'jquery', 'select2', 'wp-color-picker' ),
74 CARTFLOWS_VER,
75 true
76 );
77
78 wp_enqueue_style( 'wcf-admin-meta', CARTFLOWS_URL . 'admin/meta-assets/css/admin-edit.css', array( 'wp-color-picker' ), CARTFLOWS_VER );
79 wp_style_add_data( 'wcf-admin-meta', 'rtl', 'replace' );
80
81 $localize = array(
82 'ajax_url' => admin_url( 'admin-ajax.php' ),
83 'google_fonts' => CartFlows_Font_Families::get_google_fonts(),
84 'system_fonts' => CartFlows_Font_Families::get_system_fonts(),
85 'font_weights' => array(
86 '100' => __( 'Thin 100', 'cartflows' ),
87 '200' => __( 'Extra-Light 200', 'cartflows' ),
88 '300' => __( 'Light 300', 'cartflows' ),
89 '400' => __( 'Normal 400', 'cartflows' ),
90 '500' => __( 'Medium 500', 'cartflows' ),
91 '600' => __( 'Semi-Bold 600', 'cartflows' ),
92 '700' => __( 'Bold 700', 'cartflows' ),
93 '800' => __( 'Extra-Bold 800', 'cartflows' ),
94 '900' => __( 'Ultra-Bold 900', 'cartflows' ),
95 )
96 );
97
98 wp_localize_script( 'jquery', 'wcf', apply_filters( 'wcf_js_localize', $localize ) );
99
100 do_action( 'cartflows_admin_meta_scripts' );
101 }
102 }
103
104 /**
105 * Function to search coupons
106 */
107 public function json_search_coupons() {
108
109 check_admin_referer( 'wcf-json-search-coupons', 'security' );
110
111 global $wpdb;
112
113 $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
114
115 if ( empty( $term ) ) {
116 die();
117 }
118
119 $posts = wp_cache_get( 'wcf_search_coupons', 'wcf_funnel_Cart' );
120
121 if ( false === $posts ) {
122 $posts = $wpdb->get_results( // phpcs:ignore
123 $wpdb->prepare(
124 "SELECT *
125 FROM {$wpdb->prefix}posts
126 WHERE post_type = %s
127 AND post_title LIKE %s
128 AND post_status = %s",
129 'shop_coupon',
130 $wpdb->esc_like( $term ) . '%',
131 'publish'
132 )
133 );
134 wp_cache_set( 'wcf_search_coupons', $posts, 'wcf_funnel_Cart' );
135 }
136
137 $coupons_found = array();
138 $all_discount_types = wc_get_coupon_types();
139
140 if ( $posts ) {
141 foreach ( $posts as $post ) {
142
143 $discount_type = get_post_meta( $post->ID, 'discount_type', true );
144
145 if ( ! empty( $all_discount_types[ $discount_type ] ) ) {
146 $coupons_found[ get_the_title( $post->ID ) ] = get_the_title( $post->ID ) . ' (Type: ' . $all_discount_types[ $discount_type ] . ')';
147 }
148 }
149 }
150
151 wp_send_json( $coupons_found );
152 }
153
154 /**
155 * [add_checkout_custom_field description]
156 *
157 * @hook wcf_add_checkout_custom_field
158 */
159 public function add_checkout_custom_field() {
160
161 check_ajax_referer( 'wcf-add-checkout-custom-field', 'security' );
162
163 $post_id = intval( $_POST['post_id'] );
164 $add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
165 $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
166 $options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
167 $label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
168 $name = sanitize_text_field( wp_unslash( $_POST['name'] ) );
169
170 if ( '' !== $name ) {
171
172 $fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
173 $field_keys = array_keys($fields);
174
175 $name = $add_to . '_' . sanitize_key( $name );
176 if( in_array($name, $field_keys) ) {
177 $name = $name . '_' . rand( 0000, 9999 );
178 }
179
180 $field_data = array(
181 'type' => $type,
182 'label' => $label,
183 'placeholder' => '',
184 'class' => array( 'form-row-wide' ),
185 'label_class' => array(),
186 'required' => true,
187 'custom' => true,
188 );
189
190 if ( 'select' === $type ) {
191
192 $options = explode( ',', $options );
193 $field_data['options'] = array();
194
195 if ( is_array( $options ) && ! empty( $options ) ) {
196
197 foreach ( $options as $key => $value ) {
198
199 $field_data['options'][ $value ] = $value;
200 }
201 }
202 }
203
204 Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
205
206 $key = sanitize_key( $name );
207 $name = 'wcf-' . $key;
208
209 $field_args = array(
210 'label' => $label,
211 'name' => $name,
212 'value' => 'yes',
213 'after' => 'Enable',
214 );
215
216 $field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> | ';
217 $field_args['after_html'] .= '<a class="wcf-cpf-action-remove">' . __( 'Remove', 'cartflows' ) . '</a>';
218 $field_args['after_html'] .= '</span>';
219
220 $field_markup = wcf()->meta->get_checkbox_field( $field_args );
221
222 if( 'billing' === $add_to ) {
223 $add_to_class = 'wcf-cb-fields';
224 } else if( 'shipping' === $add_to ) {
225 $add_to_class = 'wcf-sb-fields';
226 }
227
228 $data = array(
229 'field_data' => $field_data,
230 'field_args' => $field_args,
231 'add_to_class' => $add_to_class,
232 'markup' => $field_markup,
233 );
234
235 wp_send_json( $data );
236 }
237
238 wp_send_json( false );
239
240 }
241
242 /**
243 * [add_checkout_custom_field description]
244 *
245 * @hook wcf_add_checkout_custom_field
246 */
247 public function add_pro_checkout_custom_field() {
248
249 check_ajax_referer( 'wcf-pro-add-checkout-custom-field', 'security' );
250
251 $post_id = intval( $_POST['post_id'] );
252 $add_to = sanitize_text_field( wp_unslash( $_POST['add_to'] ) );
253 $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
254 $options = sanitize_text_field( wp_unslash( $_POST['options'] ) );
255 $label = sanitize_text_field( wp_unslash( $_POST['label'] ) );
256 $name = sanitize_text_field( wp_unslash( str_replace(' ', '_', $_POST['label'] ) ) );
257 $placeholder = sanitize_text_field( wp_unslash( $_POST['placeholder'] ) );
258 $width = sanitize_text_field( wp_unslash( $_POST['width'] ) );
259 $default_value = sanitize_text_field( wp_unslash( $_POST['default'] ) );
260 $is_required = sanitize_text_field( wp_unslash( $_POST['required'] ) );
261
262 $field_markup = '';
263
264 if ( '' !== $name ) {
265
266 $fields = Cartflows_Helper::get_checkout_fields( $add_to, $post_id );
267 $field_keys = array_keys($fields);
268
269 $name = $add_to . '_' . sanitize_key( $name );
270 if( in_array($name, $field_keys) ) {
271 $name = $name . '_' . rand( 0000, 9999 );
272 }
273
274 $field_data = array(
275 'type' => $type,
276 'label' => $label,
277 'placeholder' => $placeholder,
278 'class' => array( 'form-row-wide' ),
279 'label_class' => array(),
280 'required' => $is_required,
281 'custom' => true,
282 'default' => $default_value,
283 'options' => $options,
284 );
285
286 if ( 'select' === $type ) {
287
288 $options = explode( ',', $options );
289 $field_data['options'] = array();
290
291 if ( is_array( $options ) && ! empty( $options ) ) {
292
293 foreach ( $options as $key => $value ) {
294
295 $field_data['options'][ $value ] = $value;
296 }
297 }
298 }
299
300 $width_args = array(
301 'wcf-field-width_'.$name => $width,
302 );
303
304 Cartflows_Helper::add_checkout_field( $add_to, $name, $field_data, $post_id );
305 Cartflows_Helper::save_meta_option( $post_id, $width_args );
306
307 $key = sanitize_key( $name );
308 $name = 'wcf-' . $key;
309
310 $field_args = array(
311 'type' => $type,
312 'label' => $label,
313 'name' => $name,
314 'value' => 'yes',
315 'placeholder' => $placeholder,
316 'width' => $width,
317 'after' => 'Enable',
318 'section' => $add_to,
319 'default' => $default_value,
320 'required' => $is_required,
321 'options' => $options,
322 );
323
324 $field_args['after_html'] = '<span class="wcf-cpf-actions" data-type="billing" data-key="' . $key . '"> ';
325 $field_args['after_html'] .= '<a class="wcf-cpf-action-remove wp-ui-text-notification">'. __( 'Remove', 'cartflows' ).'</a>';
326 $field_args['after_html'] .= '</span>';
327
328 // $field_markup = wcf()->meta->get_checkbox_field( $field_args );
329
330 $field_markup .= "<li class='wcf-field-item-edit-inactive wcf-field-item ui-sortable-handle'>";
331 $field_markup .= $this->get_field_html_via_ajax($field_args);
332 $field_markup .= "</li>";
333
334 if( 'billing' === $add_to ) {
335 $add_to_class = 'billing-field-sortable';
336 $section = 'billing';
337 } else if( 'shipping' === $add_to ) {
338 $add_to_class = 'shipping-field-sortable';
339 $section = 'shipping';
340 }
341
342 $data = array(
343 'field_data' => $field_data,
344 'field_args' => $field_args,
345 'add_to_class' => $add_to_class,
346 'markup' => $field_markup,
347 'section' => $section,
348 );
349
350 wp_send_json( $data );
351 }
352
353 wp_send_json( false );
354
355 }
356
357 /**
358 * Get field html.
359 *
360 * @param array $args field arguments.
361 * @return string
362 */
363 function get_field_html_via_ajax( $field_args ) {
364
365 $value = $field_args['value'];
366
367 $is_checkbox = false;
368 $is_require = false;
369 $is_select = false;
370
371 $display = 'none';
372
373 $field_content = '';
374
375 if ( isset( $field_args['before'] ) ) {
376 $field_content .= '<span>' . $field_args['before'] . '</span>';
377 }
378 $field_content .= '<input type="hidden" name="' . $field_args['name'] . '" value="no">';
379 $field_content .= '<input type="checkbox" name="' . $field_args['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
380
381 if ( isset( $field_args['after'] ) ) {
382 $field_content .= $field_args['after'];
383 }
384
385 $type = isset( $field_args['type'] ) ? $field_args['type'] : '';
386 $label = isset( $field_args['label'] ) ? $field_args['label'] : '';
387 $help = isset( $field_args['help'] ) ? $field_args['help'] : '';
388 $after_html = isset( $field_args['after_html'] ) ? $field_args['after_html'] : '';
389 $name = isset( $field_args['name'] ) ? $field_args['name'] : '';
390 $default = isset( $field_args['default']) ? $field_args['default'] : '';
391 $required = isset( $field_args['required']) ? $field_args['required'] : '';
392 $options = isset( $field_args['options']) ? $field_args['options'] : '';
393 $width = isset( $field_args['width']) ? $field_args['width'] : '';
394 $name_class = 'field-' . $field_args['name'];
395
396 if( isset( $options ) && !empty( $options ) ){
397 $options = implode(', ', $options );
398 }else{
399 $options = '';
400 }
401
402 if( 'yes' == $required ){
403 $is_require = true;
404 }
405
406 if( 'checkbox' == $type ){
407 $is_checkbox = true;
408 }
409
410 if( 'select' == $type ){
411 $is_select = true;
412 $display = 'block';
413 }
414
415 // echo "<pre>";
416 // var_dump($after_html);
417 // echo "</pre>";
418
419 // $field_markup = wcf()->meta->get_only_checkbox_field( $field_args );
420 ob_start();
421
422 ?>
423 <div class="wcf-field-item-bar">
424 <div class="wcf-field-item-handle ui-sortable-handle">
425 <label class="dashicons <?php if( 'no' == $value ){ echo 'dashicons-hidden'; } else{ echo 'dashicons-visibility';} ?> " for="<?php echo $field_args['name']; ?>"></label>
426 <span class="item-title">
427 <span class="wcf-field-item-title"><?php echo $label; if( $is_require ) { ?> <i>*</i> <?php } ?></span>
428 <span class="is-submenu" style="display: none;">sub item</span>
429 </span>
430 <span class="item-controls">
431 <span class="dashicons dashicons-menu"></span>
432 <span class="item-order hide-if-js">
433 <a href="#" class="item-move-up" aria-label="Move up">↑</a>
434 |
435 <a href="#" class="item-move-down" aria-label="Move down">↓</a>
436 </span>
437 <a class="item-edit" id="edit-64" href="javascript:void(0);" aria-label="My account. Menu item 1 of 5."><span class="screen-reader-text">Edit</span></a>
438 </span>
439 </div>
440 </div>
441 <div class="wcf-field-item-settings">
442 <div class="wcf-field-item-settings-row-width">
443 <?php
444 echo wcf()->meta->get_select_field(
445 array(
446 'label' => __( 'Field Width', 'cartflows' ),
447 'name' => 'wcf-field-width_' . str_replace( 'wcf-', '', $field_args['name'] ),
448 'value' => $width,
449 'options' => array(
450 '33' => __( '33%', 'cartflows' ),
451 '50' => __( '50%', 'cartflows' ),
452 '100' => __( '100%', 'cartflows' ),
453 ),
454 )
455 );
456 ?>
457 </div>
458
459 <div class="wcf-field-item-settings-label">
460 <?php
461 echo wcf()->meta->get_text_field(
462 array(
463 'label' => __( 'Field Label', 'cartflows' ),
464 'name' => 'wcf_label_text_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
465 'value' => $label,
466 )
467 );
468
469 ?>
470 <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace( 'wcf-', '', $field_args['name'] ); ?>">
471 </div>
472
473 <div class="wcf-field-item-select-options" style="display:<?php if( isset( $display ) ){ print $display; } ?>;" >
474 <?php
475 echo wcf()->meta->get_text_field(
476 array(
477 'label' => __( 'Options', 'cartflows' ),
478 'name' => 'wcf_select_option_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
479 'value' => $options,
480 )
481 );
482
483 ?>
484 <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace( 'wcf-', '', $field_args['name'] ); ?>">
485 </div>
486
487 <div class="wcf-field-item-settings-default">
488 <?php
489 if( true == $is_checkbox ){
490 echo wcf()->meta->get_select_field(
491 array(
492 'label' => __( 'Default', 'cartflows' ),
493 'name' => 'wcf_label_default_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
494 'value' => $value,
495 'options' => array(
496 '1' => __( 'Checked', 'cartflows' ),
497 '0' => __( 'Un-Checked', 'cartflows' ),
498 ),
499 )
500 );
501 }else{
502
503 echo wcf()->meta->get_text_field(
504 array(
505 'label' => __( 'Default', 'cartflows' ),
506 'name' => 'wcf_label_default_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
507 'value' => $default,
508 )
509 );
510 }
511 ?>
512 </div>
513
514 <div class="wcf-field-item-settings-placeholder" <?php if( true == $is_checkbox ) {?> style="display: none;" <?php } ?> >
515 <?php
516 echo wcf()->meta->get_text_field(
517 array(
518 'label' => __( 'Placeholder', 'cartflows' ),
519 'name' => 'wcf_label_placeholder_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
520 'value' => $label,
521 )
522 );
523 ?>
524 </div>
525
526 <div class="wcf-field-item-settings-required">
527 <?php
528 echo wcf()->meta->get_checkbox_field(
529 array(
530 'label' => __( 'Required', 'cartflows' ),
531 'name' => 'wcf_is_required_field_' . $field_args['section'] . '[' . str_replace( 'wcf-', '', $field_args['name'] ) . ']',
532 'value' => $required,
533 )
534 );
535 ?>
536 </div>
537
538 <div class="wcf-field-item-settings-checkbox">
539 <?php
540 echo wcf()->meta->get_checkbox_field(
541 array(
542 'label' => __( 'Enable this field', 'cartflows' ),
543 'name' => $field_args['name'],
544 'value' => $value,
545 )
546 );
547 ?>
548 </div>
549
550 <?php
551 if(isset( $field_args['after_html']) )
552 {
553 ?>
554 <div class="wcf-field-item-settings-row-delete-cf">
555 <?php echo $field_args['after_html']; ?>
556 </div>
557 <?php
558 }
559 ?>
560 <!--
561 <label for="<?php echo $field_args['name']; ?>">
562 <?php _e( 'Label', 'cartflows' ); ?><br>
563 <input type="text" value="<?php echo $field_args['label']; ?>">
564
565 <?php if( isset( $field_markup ) ) { echo $field_markup; }?>
566
567 <input type="hidden" name="wcf_field_order_<?php echo $field_args['section']; ?>[]" value="<?php echo str_replace('wcf-', '', $field_args['name'] ); ?>">
568 </label> -->
569 </div>
570
571 <?php
572
573 return ob_get_clean();
574 }
575
576 /**
577 * [delete_checkout_custom_field description]
578 *
579 * @hook wcf_delete_checkout_custom_field
580 * @return [type] [description]
581 */
582 public function delete_checkout_custom_field() {
583
584 check_ajax_referer( 'wcf-delete-checkout-custom-field', 'security' );
585
586 $post_id = intval( $_POST['post_id'] );
587 $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
588 $key = sanitize_text_field( wp_unslash( $_POST['key'] ) );
589
590 if ( '' !== $key ) {
591
592 Cartflows_Helper::delete_checkout_field( $type, $key, $post_id );
593
594 wp_send_json( true );
595
596 }
597
598 wp_send_json( false );
599
600 }
601
602 /**
603 * Function to search coupons
604 */
605 public function json_search_pages() {
606
607 check_ajax_referer( 'wcf-json-search-pages', 'security' );
608
609 $term = (string) urldecode( sanitize_text_field( wp_unslash( $_GET['term'] ) ) ); // phpcs:ignore
610
611 if ( empty( $term ) ) {
612 die( 'not found' );
613 }
614
615 $search_string = $term;
616 $data = array();
617 $result = array();
618
619 add_filter( 'posts_search', array( $this, 'search_only_titles' ), 10, 2 );
620
621 $query = new WP_Query(
622 array(
623 's' => $search_string,
624 'post_type' => 'page',
625 'posts_per_page' => - 1,
626 )
627 );
628
629 if ( $query->have_posts() ) {
630 while ( $query->have_posts() ) {
631 $query->the_post();
632 $title = get_the_title();
633 $title .= ( 0 != $query->post->post_parent ) ? ' (' . get_the_title( $query->post->post_parent ) . ')' : '';
634 $id = get_the_id();
635 $data[] = array(
636 'id' => $id,
637 'text' => $title,
638 );
639 }
640 }
641
642 if ( is_array( $data ) && ! empty( $data ) ) {
643 $result[] = array(
644 'text' => '',
645 'children' => $data,
646 );
647 }
648
649 wp_reset_postdata();
650
651 // return the result in json.
652 wp_send_json( $result );
653 }
654
655 public function search_only_titles( $search, $wp_query ) {
656 if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
657 global $wpdb;
658
659 $q = $wp_query->query_vars;
660 $n = ! empty( $q['exact'] ) ? '' : '%';
661
662 $search = array();
663
664 foreach ( (array) $q['search_terms'] as $term ) {
665 $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
666 }
667
668 if ( ! is_user_logged_in() ) {
669 $search[] = "$wpdb->posts.post_password = ''";
670 }
671
672 $search = ' AND ' . implode( ' AND ', $search );
673 }
674
675 return $search;
676 }
677
678 function get_field( $field_data, $field_content ) {
679
680 $label = isset( $field_data['label'] ) ? $field_data['label'] : '';
681 $help = isset( $field_data['help'] ) ? $field_data['help'] : '';
682 $after_html = isset( $field_data['after_html'] ) ? $field_data['after_html'] : '';
683
684 $name_class = 'field-' . $field_data['name'];
685
686 $field_html = '<div class="wcf-field-row ' . $name_class . '">';
687
688 if( ! empty( $label ) || ! empty( $help ) ) {
689 $field_html .= '<div class="wcf-field-row-heading">';
690 if( ! empty( $label ) ) {
691 $field_html .= '<label>' . esc_html( $label ) . '</label>';
692 }
693 if ( ! empty( $help ) ) {
694 $field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help">';
695 // $field_html .= '<span class="wcf-tooltip" data-tooltip= "'. esc_attr( $help ) .'"></span>';
696 $field_html .= '</i>';
697 $field_html .= '<span class="wcf-tooltip-text">';
698 $field_html .= $help;
699 $field_html .= '</span>';
700 }
701 $field_html .= '</div>';
702 }
703
704 $field_html .= '<div class="wcf-field-row-content">';
705 $field_html .= $field_content;
706
707 if ( ! empty( $after_html ) ) {
708 $field_html .= $after_html;
709 }
710
711 $field_html .= '</div>';
712 $field_html .= '</div>';
713
714 return $field_html;
715 }
716
717 function get_text_field( $field_data ) {
718
719 $value = $field_data['value'];
720
721 $attr = '';
722
723 if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
724
725 foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
726 $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
727 }
728 }
729
730 $field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
731
732 return $this->get_field( $field_data, $field_content );
733 }
734
735 function get_shortcode_field( $field_data ) {
736
737 $attr = '';
738
739 $attr_fields = array(
740 'readonly' => 'readonly',
741 'onfocus' => 'this.select()',
742 'onmouseup' => 'return false',
743 );
744
745 if ( $attr_fields && is_array( $attr_fields ) ) {
746
747 foreach ( $attr_fields as $attr_key => $attr_value ) {
748 $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
749 }
750 }
751
752 $field_content = '<input type="text" name="' . $field_data['name'] . '" value="' . $field_data['content'] . '" ' . $attr . '>';
753
754 return $this->get_field( $field_data, $field_content );
755 }
756
757 function get_display_field( $field_data ) {
758
759 $field_content = $field_data['content'];
760
761 return $this->get_field( $field_data, $field_content );
762 }
763
764 function get_hr_line_field( $field_data ) {
765
766 $field_data = array(
767 'name' => 'wcf-hr-line',
768 'content' => '<hr>'
769 );
770
771 $field_content = $field_data['content'];
772
773 return $this->get_field( $field_data, $field_content );
774 }
775
776 function get_number_field( $field_data ) {
777
778 $value = $field_data['value'];
779
780 $attr = '';
781
782 if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
783
784 foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
785 $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
786 }
787 }
788
789 $field_content = '<input type="number" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
790
791 return $this->get_field( $field_data, $field_content );
792 }
793
794 function get_hidden_field( $field_data ) {
795
796 $value = $field_data['value'];
797
798 $attr = '';
799
800 if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
801
802 foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
803 $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
804 }
805 }
806
807 $field_content = '<input type="hidden" id="' . $field_data['name'] . '" name="' . $field_data['name'] . '" value="' . $value . '" ' . $attr . '>';
808
809 return $this->get_field( $field_data, $field_content );
810 }
811
812 function get_area_field( $field_data ) {
813
814 $value = $field_data['value'];
815
816 $field_content = '<textarea name="' . $field_data['name'] . '" rows="10" cols="50">';
817 $field_content .= $value;
818 $field_content .= '</textarea>';
819
820 return $this->get_field( $field_data, $field_content );
821 }
822
823 function get_only_checkbox_field( $field_data ) {
824 // echo "<pre>";
825 // var_dump($field_data);
826 // echo "</pre>";
827
828 $value = $field_data['value'];
829
830
831 $field_content = '';
832 if ( isset( $field_data['before'] ) ) {
833 $field_content .= '<span>' . $field_data['before'] . '</span>';
834 }
835 $field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
836 $field_content .= '<input type="checkbox" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
837
838 if ( isset( $field_data['after'] ) ) {
839 $field_content .= '<span>' . $field_data['after'] . '</span>';
840 }
841
842 if ( isset( $field_data['after_html'] ) ) {
843 $field_content .= '<span>' . $field_data['after_html'] . '</span>';
844 }
845
846 return $field_content;
847 }
848
849 function get_checkbox_field( $field_data ) {
850
851 $value = $field_data['value'];
852
853 $field_content = '';
854 if ( isset( $field_data['before'] ) ) {
855 $field_content .= '<span>' . $field_data['before'] . '</span>';
856 }
857 $field_content .= '<input type="hidden" name="' . $field_data['name'] . '" value="no">';
858 $field_content .= '<input type="checkbox" id="'.$field_data['name'].'" name="' . $field_data['name'] . '" value="yes" ' . checked( 'yes', $value, false ) . '>';
859
860 if ( isset( $field_data['after'] ) ) {
861 $field_content .= '<span>' . $field_data['after'] . '</span>';
862 }
863
864 return $this->get_field( $field_data, $field_content );
865 }
866
867 function get_radio_field( $field_data ) {
868
869 $value = $field_data['value'];
870 $field_content = '';
871
872 if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
873
874 foreach ( $field_data['options'] as $data_key => $data_value ) {
875
876 $field_content .= '<div class="wcf-radio-option">';
877 $field_content .= '<input type="radio" name="' . $field_data['name'] . '" value="' . $data_key . '" ' . checked( $data_key, $value, false ) . '>';
878 $field_content .= $data_value;
879 $field_content .= '</div>';
880 }
881 }
882
883 return $this->get_field( $field_data, $field_content );
884 }
885
886 function get_font_family_field( $field_data ) {
887
888 $value = $field_data['value'];
889
890 $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
891
892 $field_content = '<select class="wcf-field-font-family" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
893
894 $field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
895
896 $field_content .= '<optgroup label="Other System Fonts">';
897 foreach ( CartFlows_Font_Families::get_system_fonts() as $name => $variants ) {
898 $field_content .= '<option value="' . esc_attr( $name ) . '" ' . selected( $name, $value, false ) . '>' . esc_attr( $name ) . '</option>';
899 }
900 $field_content .= '</optgroup>';
901 $field_content .= '<optgroup label="Google">';
902 foreach ( CartFlows_Font_Families::get_google_fonts() as $name => $single_font ) {
903 $variants = wcf_get_prop( $single_font, '0' );
904 $category = wcf_get_prop( $single_font, '1' );
905 $font_value = '\'' . esc_attr( $name ) . '\', ' . esc_attr( $category );
906 $field_content .= '<option value="' . esc_attr( $font_value ) . '" ' . selected( $font_value, $value, false ) . '>' . esc_attr( $name ) . '</option>';
907 }
908 $field_content .= '</optgroup>';
909
910 $field_content .= '</select>';
911
912 return $this->get_field( $field_data, $field_content );
913 }
914
915 function get_font_weight_field( $field_data ) {
916
917 $value = $field_data['value'];
918
919 $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
920
921 $field_content = '<select data-selected="'.esc_attr( $value ).'" class="wcf-field-font-weight" data-for="' . $field_data['for'] . '" name="' . $field_data['name'] . '">';
922
923 $field_content .= '<option value="" ' . selected( '', $value, false ) . '>Default</option>';
924
925 $field_content .= '</select>';
926
927 return $this->get_field( $field_data, $field_content );
928 }
929
930 function get_select_field( $field_data ) {
931
932 $value = $field_data['value'];
933 $pro_options = isset( $field_data['pro-options'] ) ? $field_data['pro-options'] : array();
934
935 $field_content = '<select name="' . $field_data['name'] . '">';
936
937
938 if ( is_array( $field_data['options'] ) && ! empty( $field_data['options'] ) ) {
939
940 foreach ( $field_data['options'] as $data_key => $data_value ) {
941
942 $disabled = '';
943
944 if ( array_key_exists( $data_key, $pro_options ) ) {
945 $disabled = 'disabled ';
946 $data_value = $pro_options[ $data_key ];
947 }
948
949 $field_content .= '<option value="' . $data_key . '" ' . selected( $value, $data_key, false ) . ' ' . $disabled .'>' . $data_value . '</option>';
950 }
951 }
952
953 $field_content .= '</select>';
954
955 if ( isset( $field_data['after'] ) ) {
956 $field_content .= '<span>' . $field_data['after'] . '</span>';
957 }
958
959 return $this->get_field( $field_data, $field_content );
960 }
961
962 function get_color_picker_field( $field_data ) {
963
964 $value = $field_data['value'];
965
966 $field_content = '<input class="wcf-color-picker" type="text" name="' . $field_data['name'] . '" value="' . $value . '">';
967
968 return $this->get_field( $field_data, $field_content );
969 }
970
971 function get_product_selection_field( $field_data ) {
972
973 $value = $field_data['value'];
974
975 $multiple = '';
976
977 if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
978 $multiple = ' multiple="multiple"';
979 }
980
981 $allow_clear = '';
982
983 if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
984 $allow_clear = ' data-allow_clear="allow_clear"';
985 }
986
987 $field_content = '<select
988 name="' . $field_data['name'] . '[]"
989 class="wcf-product-search" ' . $multiple . $allow_clear . '
990 data-placeholder="' . __( 'Search for a product&hellip;', 'cartflows' ) . '"
991 data-action="woocommerce_json_search_products_and_variations">';
992
993 if ( is_array( $value ) && ! empty( $value ) ) {
994
995 foreach ( $value as $data_key => $product_id ) {
996
997 $product = wc_get_product( $product_id );
998
999 // posts.
1000 if ( ! empty( $product ) ) {
1001 $post_title = $product->get_name() . ' (#' . $product_id . ')';
1002
1003 $field_content .= '<option value="' . $product_id . '" selected="selected" >' . $post_title . '</option>';
1004 }
1005 }
1006 }
1007 $field_content .= '</select>';
1008
1009 return $this->get_field( $field_data, $field_content );
1010 }
1011
1012 function get_coupon_selection_field( $field_data ) {
1013
1014 $value = $field_data['value'];
1015
1016 $multiple = '';
1017
1018 if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
1019 $multiple = ' multiple="multiple"';
1020 }
1021
1022 $allow_clear = '';
1023
1024 if ( isset( $field_data['allow_clear'] ) && $field_data['allow_clear'] ) {
1025 $allow_clear = ' data-allow_clear="allow_clear"';
1026 }
1027
1028 $field_content = '<select
1029 name="' . $field_data['name'] . '[]"
1030 class="wc-coupon-search wcf-coupon-search" ' . $multiple . $allow_clear . '
1031 data-placeholder="' . __( 'Search for a coupon&hellip;', 'cartflows' ) . '"
1032 data-action="wcf_json_search_coupons">';
1033
1034 if ( is_array( $value ) && ! empty( $value ) ) {
1035
1036 $all_discount_types = wc_get_coupon_types();
1037
1038 foreach ( $value as $coupon_title ) {
1039
1040 $coupon = new WC_Coupon( $coupon_title );
1041
1042 $discount_type = $coupon->get_discount_type();
1043
1044 if ( isset( $discount_type ) && $discount_type ) {
1045 $discount_type = ' ( Type: ' . $all_discount_types[ $discount_type ] . ' )';
1046 }
1047
1048 $field_content .= '<option value="' . $coupon_title . '" selected="selected">' . $coupon_title . $discount_type . '</option>';
1049 }
1050 }
1051
1052 $field_content .= '</select>';
1053
1054 return $this->get_field( $field_data, $field_content );
1055 }
1056
1057 function get_page_selection_field( $field_data ) {
1058
1059 $value = $field_data['value'];
1060
1061 $multiple = '';
1062
1063 if ( isset( $field_data['multiple'] ) && $field_data['multiple'] ) {
1064 $multiple = 'multiple="multiple"';
1065 }
1066
1067 $field_content = '<select
1068 name="' . $field_data['name'] . '[]"
1069 class="wcf-search-pages" ' . $multiple . '"
1070 data-action="wcf_json_search_pages">';
1071
1072 if ( is_array( $value ) && ! empty( $value ) ) {
1073
1074 foreach ( $value as $data_key => $data_value ) {
1075
1076 $field_content .= '<option value="' . $data_value . '">' . get_the_title( $data_value ) . '</option>';
1077 }
1078 }
1079
1080 $field_content .= '</select>';
1081
1082 return $this->get_field( $field_data, $field_content );
1083 }
1084
1085 function get_section( $field_data ) {
1086 $field_html = '<div class="wcf-field-row wcf-field-section">';
1087 $field_html .= '<div class="wcf-field-section-heading" colspan="2">';
1088 $field_html .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1089
1090 if ( isset( $field_data['help'] ) ) {
1091 $field_html .= '<i class="wcf-field-heading-help dashicons dashicons-editor-help" title="' . esc_attr( $field_data['help'] ) . '"></i>';
1092 }
1093 $field_html .= '</div>';
1094 $field_html .= '</div>';
1095 return $field_html;
1096 }
1097
1098 function get_description_field( $field_data ) {
1099
1100 $field_html = '<div class="wcf-field-row wcf-field-desc ' . $field_data['name'] . '">';
1101 $field_html .= '<div class="wcf-field-desc-content">';
1102 $field_html .= $field_data['content'];
1103 $field_html .= '</div>';
1104 $field_html .= '</div>';
1105
1106 return $field_html;
1107 }
1108
1109 function get_checkout_field_repeater( $field_data ) {
1110
1111 $value = array();
1112
1113 $value[0] = array(
1114 'add_to' => '',
1115 'type' => '',
1116 'label' => '',
1117 'name' => '',
1118 );
1119
1120 $field_content = '';
1121
1122 $field_content .= '<div class="wcf-field-row">';
1123 // $field_content .= '<div class="wcf-field-row-heading">';
1124 // $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1125 // $field_content .= '</div>';
1126 $field_content .= '<div class="wcf-field-row-content">';
1127 $field_content .= '<div class="wcf-cpf-wrap">';
1128
1129 foreach ( $value as $p_key => $p_data ) {
1130 $field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
1131 $field_content .= '<div class="wcf-cpf-row-header">';
1132 $field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
1133 $field_content .= '</div>';
1134
1135 $field_content .= '<div class="wcf-cpf-row-standard-fields">';
1136
1137 /* Add To */
1138 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
1139 $field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
1140 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1141 $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
1142 $field_content .= '<option value="billing">Billing</option>';
1143 $field_content .= '<option value="shipping">Shipping</option>';
1144 $field_content .= '</select>';
1145 $field_content .= '</span>';
1146 $field_content .= '</div>';
1147
1148 /* Type */
1149 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
1150 $field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
1151 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1152 $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
1153 $field_content .= '<option value="text">Text</option>';
1154 $field_content .= '<option value="textarea">Textarea</option>';
1155 $field_content .= '<option value="select">Select</option>';
1156 $field_content .= '<option value="checkbox">Checkbox</option>';
1157 $field_content .= '</select>';
1158 $field_content .= '</span>';
1159 $field_content .= '</div>';
1160
1161 /* Textarea */
1162 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
1163 $field_content .= '<span class="wcf-cpf-row-setting-label">Options *</span>';
1164 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1165 $field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
1166 $field_content .= '</span>';
1167 $field_content .= '</div>';
1168
1169 /* Label */
1170 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
1171 $field_content .= '<span class="wcf-cpf-row-setting-label">Label *</span>';
1172 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1173 $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
1174 $field_content .= '</span>';
1175 $field_content .= '</div>';
1176
1177 /* Name */
1178 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-name">';
1179 $field_content .= '<span class="wcf-cpf-row-setting-label">Name *</span>';
1180 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1181 $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][name]" class="wcf-cpf-name">';
1182 $field_content .= '</span>';
1183 $field_content .= '</div>';
1184
1185 $field_content .= '</div>';
1186 $field_content .= '</div>';
1187 }
1188
1189 /* Add New Custom Field */
1190 $field_content .= '<div class="wcf-cpf-add-row">';
1191 $field_content .= '<div class="wcf-cpf-add-wrap">';
1192 $field_content .= '<button class="button button-secondary wcf-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
1193 $field_content .= '</div>';
1194 $field_content .= '</div>';
1195 /* End Add new custom field */
1196
1197 $field_content .= '</div>';
1198 $field_content .= '</div>';
1199 $field_content .= '</div>';
1200
1201 return $field_content;
1202 }
1203
1204 function get_pro_checkout_field_repeater( $field_data ) {
1205
1206 $value = array();
1207
1208 $value[0] = array(
1209 'add_to' => '',
1210 'type' => '',
1211 'label' => '',
1212 'name' => '',
1213 );
1214
1215 $field_content = '';
1216
1217 $field_content .= '<div class="wcf-field-row">';
1218 // $field_content .= '<div class="wcf-field-row-heading">';
1219 // $field_content .= '<label>' . esc_html( $field_data['label'] ) . '</label>';
1220 // $field_content .= '</div>';
1221 $field_content .= '<div class="wcf-field-row-content">';
1222 $field_content .= '<div class="wcf-cpf-wrap">';
1223
1224 foreach ( $value as $p_key => $p_data ) {
1225 $field_content .= '<div class="wcf-cpf-row" data-key="' . $p_key . '">';
1226 $field_content .= '<div class="wcf-cpf-row-header">';
1227 $field_content .= '<span class="wcf-cpf-row-title">Add New Custom Field</span>';
1228 $field_content .= '</div>';
1229
1230 $field_content .= '<div class="wcf-cpf-row-standard-fields">';
1231
1232 /* Add To */
1233 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-add_to">';
1234 $field_content .= '<span class="wcf-cpf-row-setting-label">Add to</span>';
1235 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1236 $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][add_to]" class="wcf-cpf-add_to">';
1237 $field_content .= '<option value="billing">Billing</option>';
1238 $field_content .= '<option value="shipping">Shipping</option>';
1239 $field_content .= '</select>';
1240 $field_content .= '</span>';
1241 $field_content .= '</div>';
1242
1243 /* Type */
1244 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-type">';
1245 $field_content .= '<span class="wcf-cpf-row-setting-label">Type</span>';
1246 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1247 $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][type]" class="wcf-cpf-type">';
1248 $field_content .= '<option value="text">Text</option>';
1249 $field_content .= '<option value="textarea">Textarea</option>';
1250 $field_content .= '<option value="select">Select</option>';
1251 $field_content .= '<option value="checkbox">Checkbox</option>';
1252 $field_content .= '<option value="hidden">Hidden</option>';
1253 $field_content .= '</select>';
1254 $field_content .= '</span>';
1255 $field_content .= '</div>';
1256
1257 /* Label */
1258 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-label">';
1259 $field_content .= '<span class="wcf-cpf-row-setting-label">Label <i>*</i></span>';
1260 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1261 $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-label">';
1262 $field_content .= '<span id="wcf-cpf-label-error-msg"></span>';
1263 $field_content .= '</span>';
1264 $field_content .= '</div>';
1265
1266 /* Default */
1267 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-default">';
1268 $field_content .= '<span class="wcf-cpf-row-setting-label">Default</span>';
1269 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1270 $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][default]" class="wcf-cpf-default">';
1271 $field_content .= '<span id="wcf-cpf-default-error-msg"></span>';
1272 $field_content .= '</span>';
1273 $field_content .= '</div>';
1274
1275 /* Placeholder */
1276 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-placeholder">';
1277 $field_content .= '<span class="wcf-cpf-row-setting-label">Placeholder</span>';
1278 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1279 $field_content .= '<input type="text" value="" name="wcf-checkout-custom-fields[' . $p_key . '][placeholder]" class="wcf-cpf-placeholder">';
1280 $field_content .= '<span id="wcf-cpf-placeholder-error-msg"></span>';
1281 $field_content .= '</span>';
1282 $field_content .= '</div>';
1283
1284 /* Options */
1285 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-options">';
1286 $field_content .= '<span class="wcf-cpf-row-setting-label">Options <i>*</i></span>';
1287 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1288 $field_content .= '<textarea value="" name="wcf-checkout-custom-fields[' . $p_key . '][label]" class="wcf-cpf-options" placeholder="Enter your options separated by comma."></textarea>';
1289 $field_content .= '</span>';
1290 $field_content .= '</div>';
1291
1292 /* Width */
1293 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-width">';
1294 $field_content .= '<span class="wcf-cpf-row-setting-label">Width</span>';
1295 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1296 $field_content .= '<select name="wcf-checkout-custom-fields[' . $p_key . '][width]" class="wcf-cpf-width">';
1297 $field_content .= '<option value="33">33%</option>';
1298 $field_content .= '<option value="50">50%</option>';
1299 $field_content .= '<option value="100" selected>100%</option>';
1300 $field_content .= '</select>';
1301 $field_content .= '</span>';
1302 $field_content .= '</div>';
1303
1304 /* Required */
1305 $field_content .= '<div class="wcf-cpf-fields wcf-cpf-required">';
1306 $field_content .= '<span class="wcf-cpf-row-setting-label">Required</span>';
1307 $field_content .= '<span class="wcf-cpf-row-setting-field">';
1308 $field_content .= '<input type="hidden" value="no" name="wcf-checkout-custom-fields[' . $p_key . '][required]" class="wcf-cpf-required">';
1309 $field_content .= '<input type="checkbox" value="yes" name="wcf-checkout-custom-fields[' . $p_key . '][required]" class="wcf-cpf-required">';
1310 $field_content .= '<span id="wcf-cpf-required-error-msg"></span>';
1311 $field_content .= '</span>';
1312 $field_content .= '</div>';
1313
1314 $field_content .= '</div>';
1315 $field_content .= '</div>';
1316 }
1317
1318 /* Add New Custom Field */
1319 $field_content .= '<div class="wcf-cpf-add-row">';
1320 $field_content .= '<div class="wcf-cpf-add-wrap">';
1321 $field_content .= '<button class="button button-secondary wcf-pro-cpf-add" data-name="wcf-checkout-custom-fields">Add New Field</button>';
1322 $field_content .= '</div>';
1323 $field_content .= '</div>';
1324 /* End Add new custom field */
1325
1326 $field_content .= '</div>';
1327 $field_content .= '</div>';
1328 $field_content .= '</div>';
1329
1330 return $field_content;
1331 }
1332
1333 function get_product_selection_repeater( $field_data ) {
1334
1335 $value = $field_data['value'];
1336
1337 if ( ! is_array( $value ) ) {
1338
1339 $value[0] = array(
1340 'product' => '',
1341 );
1342 } else {
1343
1344 if ( ! isset( $value[0] ) ) {
1345
1346 $value[0] = array(
1347 'product' => '',
1348 );
1349 }
1350 }
1351
1352 $field_html = '';
1353
1354 $field_html .= '<script type="text/html" id="tmpl-wcf-product-repeater">';
1355 $field_html .= $this->generate_product_repeater_html( '{{id}}' );
1356 $field_html .= '</script>';
1357
1358 $field_html .= '<div class="wcf-field-row">';
1359 $field_html .= '<div class="wcf-field-row-content">';
1360 $field_html .= '<div class="wcf-repeatables-wrap">';
1361
1362 if ( is_array( $value ) ) {
1363
1364 foreach ( $value as $p_key => $p_data ) {
1365
1366 $selected_options = '';
1367
1368 if ( isset( $p_data['product'] ) ) {
1369
1370 $product = wc_get_product( $p_data['product'] );
1371
1372 // posts.
1373 if ( ! empty( $product ) ) {
1374 $post_title = $product->get_name() . ' (#' . $p_data['product'] . ')';
1375
1376 $selected_options = '<option value="' . $p_data['product'] . '" selected="selected" >' . $post_title . '</option>';
1377 }
1378 }
1379
1380 $field_html .= $this->generate_product_repeater_html( $p_key, $selected_options );
1381 }
1382 }
1383
1384 $field_html .= '<div class="wcf-add-repeatable-row">';
1385 $field_html .= '<div class="submit wcf-add-repeatable-wrap">';
1386 $field_html .= '<button class="button-primary wcf-add-repeatable" data-name="wcf-checkout-products">Add New Product</button>';
1387 $field_html .= '</div>';
1388 $field_html .= '</div>';
1389 $field_html .= '</div>';
1390 $field_html .= '</div>';
1391 $field_html .= '</div>';
1392
1393 return $field_html;
1394 }
1395
1396 function generate_product_repeater_html( $id, $options = '' ) {
1397
1398 $field_html = '<div class="wcf-repeatable-row" data-key="' . $id . '">';
1399
1400 $field_html .= '<div class="wcf-repeatable-row-standard-fields">';
1401
1402 /* Product Name */
1403 $field_html .= '<div class="wcf-repeatable-fields wcf-sel-product">';
1404 $field_html .= '<span class="wcf-repeatable-row-setting-field">';
1405 $field_html .= '<select
1406 name="wcf-checkout-products[' . $id . '][product]"
1407 class="wcf-product-search"
1408 data-allow_clear="allow_clear"
1409 data-placeholder="' . __( 'Search for a product&hellip;', 'cartflows' ) . '"
1410 data-action="woocommerce_json_search_products_and_variations">';
1411 $field_html .= $options;
1412 $field_html .= '</select>';
1413 $field_html .= '</span>';
1414 $field_html .= '<span class="wcf-repeatable-row-actions">';
1415 $field_html .= '<a class="wcf-remove-row wcf-repeatable-remove button" data-type="product">';
1416 $field_html .= '<span class="dashicons dashicons-trash"></span>';
1417 $field_html .= '<span class="wcf-repeatable-remove-button">'. __( 'Remove', 'cartflows' ).'</span>';
1418 $field_html .= '</a>';
1419 $field_html .= '</span>';
1420 $field_html .= '</div>';
1421 $field_html .= '</div>';
1422 $field_html .= '</div>';
1423
1424 return $field_html;
1425 }
1426
1427 function get_image_field( $field_data ) {
1428
1429 $value = $field_data['value'];
1430
1431 $attr = '';
1432
1433 if ( isset( $field_data['attr'] ) && is_array( $field_data['attr'] ) ) {
1434
1435 foreach ( $field_data['attr'] as $attr_key => $attr_value ) {
1436 $attr .= ' ' . $attr_key . '="' . $attr_value . '"';
1437 }
1438 }
1439
1440 $display_preview_box = ( isset( $value ) && '' != $value ) ? 'display:block;' : 'display:none';
1441
1442 $field_content = '<div id="wcf-image-preview" style="'.$display_preview_box.'">';
1443 if( isset( $value ) ){
1444 $field_content .= '<img src="'. $value .'" class="saved-image" name="'. $field_data['name'] .'" width="150">';
1445 }
1446 $field_content .= '</div>';
1447 // $field_content .= '<input type="hidden" id="wcf-image-id" class="wcf-image-id" name="wcf-image-id[image-id]" value="">';
1448 $field_content .= '<input type="hidden" id="wcf-image-value" class="wcf-image" name="' . $field_data['name'] . '" value="'.$value.'">';
1449
1450 $field_content .= '<button type="button" ' . $attr . ' class="wcf-select-image button-secondary">Select Image</button>';
1451
1452 $display_remove_button = ( isset( $value ) && '' != $value ) ? 'display:inline-block; margin-left: 5px;' : 'display:none';
1453
1454 $field_content .= '<button type="button" class="wcf-remove-image button-secondary" style="'.$display_remove_button.'">Remove Image</button>';
1455
1456 return $this->get_field( $field_data, $field_content );
1457 }
1458
1459 /**
1460 * Localize variables in admin
1461 *
1462 * @param array $vars variables.
1463 */
1464 function localize_vars( $vars ) {
1465
1466 $ajax_actions = array(
1467 'wcf_add_checkout_custom_field',
1468 'wcf_pro_add_checkout_custom_field',
1469 'wcf_delete_checkout_custom_field',
1470 'wcf_json_search_pages',
1471 'wcf_json_search_coupons'
1472 );
1473
1474 foreach ( $ajax_actions as $action ) {
1475
1476 $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) );
1477 }
1478
1479 return $vars;
1480 }
1481 }
1482 // @codingStandardsIgnoreEnd
1483