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 / modules / checkout / classes / class-cartflows-checkout-markup.php

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

1,158 lines 35.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checkout markup.
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Checkout Markup
10 *
11 * @since 1.0.0
12 */
13 class Cartflows_Checkout_Markup {
14
15 /**
16 * Member Variable
17 *
18 * @var object instance
19 */
20 private static $instance;
21
22 /**
23 * Initiator
24 */
25 public static function get_instance() {
26 if ( ! isset( self::$instance ) ) {
27 self::$instance = new self;
28 }
29 return self::$instance;
30 }
31
32 /**
33 * Constructor
34 */
35 public function __construct() {
36
37 /* Set is checkout flag */
38 add_filter( 'woocommerce_is_checkout', array( $this, 'woo_checkout_flag' ), 9999 );
39
40 add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_checkout_fields' ), 10, 2 );
41
42 /* Show notice if cart is empty */
43 add_action( 'cartflows_checkout_cart_empty', array( $this, 'display_woo_notices' ) );
44
45 /* Checkout Shortcode */
46 add_shortcode( 'cartflows_checkout', array( $this, 'checkout_shortcode_markup' ) );
47
48 /* Preconfigured cart data */
49 add_action( 'wp', array( $this, 'preconfigured_cart_data' ), 1 );
50
51 /* Embed Checkout */
52 add_action( 'wp', array( $this, 'shortcode_load_data' ), 999 );
53
54 /* Ajax Endpoint */
55 add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'get_ajax_endpoint' ) );
56
57 add_filter( 'cartflows_add_before_main_section', array( $this, 'enable_logo_in_header' ) );
58
59 add_filter( 'cartflows_primary_container_bottom', array( $this, 'show_cartflows_copyright_message' ) );
60
61 add_filter( 'woocommerce_login_redirect', array( $this, 'after_login_redirect' ), 10, 2 );
62
63 add_action( 'wp_ajax_wcf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
64 add_action( 'wp_ajax_nopriv_wcf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
65
66 add_filter( 'global_cartflows_js_localize', array( $this, 'add_localize_vars' ) );
67
68 /* Global Checkout */
69 add_action( 'template_redirect', array( $this, 'global_checkout_template_redirect' ), 1 );
70
71 add_action( 'wp_ajax_wcf_woo_remove_coupon', array( $this, 'remove_coupon' ) );
72 add_action( 'wp_ajax_nopriv_wcf_woo_remove_coupon', array( $this, 'remove_coupon' ) );
73
74 }
75
76 /**
77 * Display all WooCommerce notices.
78 *
79 * @since 1.1.5
80 */
81 function display_woo_notices() {
82
83 if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
84 woocommerce_output_all_notices();
85 }
86 }
87
88
89 /**
90 * Redirect from default to the global checkout page
91 *
92 * @since 1.0.0
93 */
94 function global_checkout_template_redirect() {
95
96 if ( ! is_checkout() ) {
97 return;
98 }
99
100 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
101 return;
102 }
103
104 // redirect only for cartflows checkout pages.
105 $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
106 $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
107
108 $common = Cartflows_Helper::get_common_settings();
109
110 $global_checkout = $common['global_checkout'];
111
112 if (
113 // ignore on order-pay.
114 false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
115 // ignore on TY page.
116 false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
117 ) {
118
119 if ( '' !== $global_checkout ) {
120
121 $link = get_permalink( $global_checkout );
122
123 if ( ! empty( $link ) ) {
124
125 wp_redirect( $link );
126 die();
127 }
128 }
129 }
130 }
131
132 /**
133 * Check for checkout flag
134 *
135 * @param bool $is_checkout is checkout.
136 *
137 * @return bool
138 */
139 function woo_checkout_flag( $is_checkout ) {
140
141 if ( ! is_admin() ) {
142
143 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
144
145 $is_checkout = true;
146 }
147 }
148
149 return $is_checkout;
150 }
151
152 /**
153 * Render checkout shortcode markup.
154 *
155 * @param array $atts attributes.
156 * @return string
157 */
158 function checkout_shortcode_markup( $atts ) {
159
160 if ( ! function_exists( 'wc_print_notices' ) ) {
161 return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
162 }
163
164 $atts = shortcode_atts(
165 array(
166 'id' => 0,
167 ),
168 $atts
169 );
170
171 $checkout_id = intval( $atts['id'] );
172
173 if ( empty( $checkout_id ) ) {
174
175 if ( ! _is_wcf_checkout_type() ) {
176
177 return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
178 }
179
180 global $post;
181
182 $checkout_id = intval( $post->ID );
183 }
184
185 $output = '';
186
187 ob_start();
188
189 do_action( 'cartflows_checkout_form_before', $checkout_id );
190
191 $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
192
193 $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
194
195 $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
196
197 if ( file_exists( $template_layout ) ) {
198 include $template_layout;
199 } else {
200 include $template_default;
201 }
202
203 $output .= ob_get_clean();
204
205 return $output;
206 }
207
208 /**
209 * Configure Cart Data.
210 *
211 * @since 1.0.0
212 *
213 * @return void
214 */
215 function preconfigured_cart_data() {
216
217 if ( is_admin() ) {
218 return;
219 }
220
221 global $post;
222
223 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
224
225 if ( wp_doing_ajax() ) {
226
227 return;
228 } else {
229
230 if ( _is_wcf_checkout_type() ) {
231 $checkout_id = $post->ID;
232 } else {
233 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
234 }
235
236 do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
237
238 $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
239
240 if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
241 $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
242 } else {
243 $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
244 }
245
246 if ( ! is_array( $products ) ) {
247
248 if ( 'dummy' === $products ) {
249
250 $args = array(
251 'posts_per_page' => 1,
252 'orderby' => 'rand',
253 'post_type' => 'product',
254 'meta_query' => array(
255 // Exclude out of stock products.
256 array(
257 'key' => '_stock_status',
258 'value' => 'outofstock',
259 'compare' => 'NOT IN',
260 ),
261 ),
262 'tax_query' => array(
263 array(
264 'taxonomy' => 'product_type',
265 'field' => 'slug',
266 'terms' => 'simple',
267 ),
268 ),
269 );
270
271 $random_product = get_posts( $args );
272
273 if ( isset( $random_product[0]->ID ) ) {
274 $products = array(
275 array(
276 'product' => $random_product[0]->ID,
277 ),
278 );
279 } else {
280 return;
281 }
282 } else {
283 return;
284 }
285 }
286
287 if ( is_array( $products ) && count( $products ) < 1 ) {
288
289 return;
290 }
291 /* Empty the current cart */
292 WC()->cart->empty_cart();
293
294 /* Set customer session if not set */
295 if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
296 WC()->session->set_customer_session_cookie( true );
297 }
298
299 $cart_product_count = 0;
300
301 foreach ( $products as $index => $data ) {
302
303 if ( ! isset( $data['product'] ) ) {
304 return;
305 }
306
307 if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
308 break;
309 }
310
311 $product_id = $data['product'];
312 $_product = wc_get_product( $product_id );
313
314 if ( ! empty( $_product ) ) {
315
316 $quantity = 1;
317
318 if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
319
320 if ( $_product->is_type( 'variable' ) ) {
321
322 $default_attributes = $_product->get_default_attributes();
323
324 if ( ! empty( $default_attributes ) ) {
325
326 foreach ( $_product->get_children() as $variation_id ) {
327
328 $single_variation = new WC_Product_Variation( $variation_id );
329
330 if ( $default_attributes == $single_variation->get_attributes() ) {
331 WC()->cart->add_to_cart( $variation_id, $quantity );
332 $cart_product_count++;
333 }
334 }
335 } else {
336
337 $product_childrens = $_product->get_children();
338
339 if ( isset( $product_childrens[0] ) ) {
340 WC()->cart->add_to_cart( $product_childrens[0], $quantity );
341 $cart_product_count++;
342 } else {
343 echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
344 }
345 }
346 } else {
347 WC()->cart->add_to_cart( $product_id, $quantity );
348 $cart_product_count++;
349 }
350 } else {
351
352 echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
353 // WC()->cart->add_to_cart( $product_id, $quantity );.
354 }
355 }
356 }
357
358 do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
359 do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
360 }
361 }
362 }
363
364 /**
365 * Load shortcode data.
366 *
367 * @return void
368 */
369 function shortcode_load_data() {
370
371 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
372
373 add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
374
375 add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 );
376
377 /* Show notices if cart has errors */
378 add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
379
380 add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
381
382 add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
383
384 // Outputting the hidden field in checkout page.
385 add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
386 add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
387
388 remove_all_actions( 'woocommerce_checkout_billing' );
389 remove_all_actions( 'woocommerce_checkout_shipping' );
390
391 // Hook in actions once.
392 add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
393 add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
394
395 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
396
397 add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
398
399 add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
400
401 add_filter( 'woocommerce_cart_totals_coupon_html', array( $this, 'remove_coupon_text' ) );
402 global $post;
403
404 if ( _is_wcf_checkout_type() ) {
405 $checkout_id = $post->ID;
406 } else {
407 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
408 }
409
410 do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
411 }
412 }
413
414 /**
415 * Render checkout ID hidden field.
416 *
417 * @param array $checkout checkout session data.
418 * @return void
419 */
420 function checkout_shortcode_post_id( $checkout ) {
421
422 global $post;
423
424 if ( _is_wcf_checkout_type() ) {
425 $checkout_id = $post->ID;
426 } else {
427 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
428 }
429
430 $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
431
432 echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
433 echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
434 }
435
436 /**
437 * Load shortcode scripts.
438 *
439 * @return void
440 */
441 function shortcode_scripts() {
442
443 wp_enqueue_style( 'wcf-checkout-template', wcf()->utils->get_css_url( 'checkout-template' ), '', CARTFLOWS_VER );
444
445 wp_enqueue_script(
446 'wcf-checkout-template',
447 wcf()->utils->get_js_url( 'checkout-template' ),
448 array( 'jquery' ),
449 CARTFLOWS_VER,
450 true
451 );
452
453 do_action( 'cartflows_checkout_scripts' );
454
455 $style = $this->generate_style();
456
457 wp_add_inline_style( 'wcf-checkout-template', $style );
458
459 }
460
461 /**
462 * Load compatibility scripts.
463 *
464 * @return void
465 */
466 function compatibility_scripts() {
467
468 global $post;
469
470 if ( _is_wcf_checkout_type() ) {
471 $checkout_id = $post->ID;
472 } else {
473 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
474 }
475
476 // Add DIVI Compatibility css if DIVI theme is enabled.
477 if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
478 Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id )
479 ) {
480 wp_enqueue_style( 'wcf-checkout-template-divi', wcf()->utils->get_css_url( 'checkout-template-divi' ), '', CARTFLOWS_VER );
481 }
482
483 // Add Flatsome Compatibility css if Flatsome theme is enabled.
484 if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
485 wp_enqueue_style( 'wcf-checkout-template-flatsome', wcf()->utils->get_css_url( 'checkout-template-flatsome' ), '', CARTFLOWS_VER );
486 }
487
488 // Add The7 Compatibility css if The7 theme is enabled.
489 if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) {
490 wp_enqueue_style( 'wcf-checkout-template-the-seven', wcf()->utils->get_css_url( 'checkout-template-the-seven' ), '', CARTFLOWS_VER );
491 }
492 }
493
494 /**
495 * Generate styles.
496 *
497 * @return string
498 */
499 function generate_style() {
500
501 global $post;
502
503 if ( _is_wcf_checkout_type() ) {
504 $checkout_id = $post->ID;
505 } else {
506 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
507 }
508
509 CartFlows_Font_Families::render_fonts( $checkout_id );
510
511 $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
512
513 $base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' );
514
515 $header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' );
516
517 /*$base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/
518 $r = '';
519 $g = '';
520 $b = '';
521
522 $field_tb_padding = '';
523 $field_lr_padding = '';
524
525 $field_heading_color = '';
526 $field_color = '';
527 $field_bg_color = '';
528 $field_border_color = '';
529 $field_label_color = '';
530 $submit_tb_padding = '';
531 $submit_lr_padding = '';
532 $hl_bg_color = '';
533 $field_input_size = '';
534 $box_border_color = '';
535 $section_bg_color = '';
536 $submit_button_height = '';
537 $submit_color = '';
538 $submit_bg_color = $primary_color;
539 $submit_border_color = $primary_color;
540
541 $submit_hover_color = '';
542 $submit_bg_hover_color = $primary_color;
543 $submit_border_hover_color = $primary_color;
544
545 $section_heading_color = '';
546
547 $is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' );
548
549 $button_font_family = '';
550 $button_font_weight = '';
551 $input_font_family = '';
552 $input_font_weight = '';
553 $heading_font_family = '';
554 $heading_font_weight = '';
555 $base_font_family = $base_font_family;
556 /*$base_font_weight = $base_font_weight;*/
557
558 if ( 'yes' == $is_advance_option ) {
559
560 /**
561 * Get Font Family and Font Weight weight values
562 */
563 $section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' );
564
565 $heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' );
566 $heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' );
567 $section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' );
568 $button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' );
569 $button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' );
570 $input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' );
571 $input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' );
572 $field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' );
573 $field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' );
574 $field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' );
575
576 $field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' );
577
578 $field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' );
579
580 $field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' );
581
582 $field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' );
583
584 $field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' );
585
586 $submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' );
587
588 $submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' );
589
590 $submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' );
591
592 $submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color );
593
594 $submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color );
595
596 $submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color );
597
598 $submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' );
599
600 $submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color );
601
602 $hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' );
603
604 $box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' );
605
606 $submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' );
607
608 /**
609 * Get font values
610 */
611
612 if ( 'custom' == $submit_button_height ) {
613 $submit_button_height = '38px';
614 }
615
616 if ( 'custom' == $field_input_size ) {
617 $field_input_size = '38px';
618 }
619 }
620 if ( isset( $primary_color ) ) {
621
622 list($r, $g, $b) = sscanf( $primary_color, '#%02x%02x%02x' );
623 }
624 $output = "
625 .wcf-embed-checkout-form .wcf-checkout-header-image img{
626 width: {$header_logo_width}px;
627 }
628 .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:checked:before,
629 .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:before{
630 color: {$primary_color};
631 }
632 .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:before{
633 background-color: {$primary_color};
634 }
635 .wcf-embed-checkout-form .woocommerce #payment input[type=checkbox]:focus,
636 .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:focus,
637 .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:checked:focus,
638 .wcf-embed-checkout-form .woocommerce #payment input[type=radio]:not(:checked):focus{
639 border-color: {$primary_color};
640 box-shadow: 0 0 2px rgba( " . $r . ',' . $g . ',' . $b . ", .8);
641 }
642 .wcf-embed-checkout-form .woocommerce-checkout label{
643 color: {$field_label_color};
644 }
645 .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
646 background-color: {$hl_bg_color};
647 font-family: {$input_font_family};
648 font-weight: {$input_font_weight};
649 }
650
651 .wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
652 .wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
653 .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
654 {
655 border-bottom-color: {$hl_bg_color};
656 border-right-color: transparent;
657 border-left-color: transparent;
658 border-top-color: transparent;
659 position: absolute;
660 }
661
662 .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
663 .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
664 font-family: {$input_font_family};
665 font-weight: {$input_font_weight};
666 }
667
668 .wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
669 .wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
670 .wcf-embed-checkout-form .woocommerce form .form-row textarea,
671 .wcf-embed-checkout-form .select2-container--default .select2-selection--single {
672 color: {$field_color};
673 background: {$field_bg_color};
674 border-color: {$field_border_color};
675 padding-top: {$field_tb_padding}px;
676 padding-bottom: {$field_tb_padding}px;
677 padding-left: {$field_lr_padding}px;
678 padding-right: {$field_lr_padding}px;
679 min-height: {$field_input_size};
680 font-family: {$input_font_family};
681 font-weight: {$input_font_weight};
682 }
683
684 .wcf-embed-checkout-form .woocommerce .col2-set .col-1,
685 .wcf-embed-checkout-form .woocommerce .col2-set .col-2,
686 .wcf-embed-checkout-form .woocommerce-checkout .shop_table,
687 .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
688 .wcf-embed-checkout-form .woocommerce-checkout #payment,
689 .wcf-embed-checkout-form .woocommerce form.checkout_coupon
690 {
691 background-color: {$section_bg_color};
692 border-color: {$box_border_color};
693 font-family: {$input_font_family};
694 font-weight: {$input_font_weight};
695 }
696
697 .woocommerce table.shop_table th{
698 color: {$field_label_color};
699 }
700 /*.wcf-embed-checkout-form .woocommerce .woocommerce-info,
701 .wcf-embed-checkout-form .woocommerce-message{
702 border-top-color: {$primary_color};
703 background-color: {$hl_bg_color};
704 }*/
705 .wcf-embed-checkout-form .woocommerce a{
706 color: {$primary_color};
707 }
708 .wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
709 color: {$field_color};
710 }
711 .wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
712 color: {$field_color};
713 }
714 .wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
715 color: {$field_color};
716 }
717 .wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
718 color: {$field_color};
719 }
720 .wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
721 color: {$field_color};
722 }
723 .wcf-embed-checkout-form .woocommerce form p.form-row label {
724 color: {$field_label_color};
725 font-family: {$input_font_family};
726 font-weight: {$input_font_weight};
727 }
728 .wcf-embed-checkout-form .woocommerce #order_review button,
729 .wcf-embed-checkout-form .woocommerce form.woocommerce-form-login .form-row button,
730 .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small {
731 color: {$submit_color};
732 background: {$submit_bg_color};
733 padding-top: {$submit_tb_padding}px;
734 padding-bottom: {$submit_tb_padding}px;
735 padding-left: {$submit_lr_padding}px;
736 padding-right: {$submit_lr_padding}px;
737 border-color: {$submit_border_color};
738 min-height: {$submit_button_height};
739 font-family: {$button_font_family};
740 font-weight: {$button_font_weight};
741 }
742 .wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
743 .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
744 background: {$submit_bg_color};
745 border: 1px {$submit_border_color} solid;
746 color: {$submit_color};
747 min-height: {$submit_button_height};
748 font-family: {$button_font_family};
749 font-weight: {$button_font_weight};
750 }
751 .wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
752 .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
753 .wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
754 .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
755 color: {$submit_hover_color};
756 background-color: {$submit_bg_hover_color};
757 border-color: {$submit_border_hover_color};
758 }
759 .wcf-embed-checkout-form .woocommerce h3,
760 .wcf-embed-checkout-form .woocommerce h3 span,
761 .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
762 color: {$section_heading_color};
763 font-family: {$heading_font_family};
764 font-weight: {$heading_font_weight};
765 }
766 .wcf-embed-checkout-form .woocommerce-info::before,
767 .wcf-embed-checkout-form .woocommerce-message::before{
768 color: {$primary_color};
769 }
770 .wcf-embed-checkout-form{
771 font-family: {$base_font_family};
772 }
773 img.emoji, img.wp-smiley {}";
774
775 return $output;
776 }
777
778 /**
779 * Get ajax end points.
780 *
781 * @param string $endpoint_url end point URL.
782 * @return string
783 */
784 function get_ajax_endpoint( $endpoint_url ) {
785
786 global $post;
787
788 if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
789
790 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
791
792 if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
793
794 $query_args = array(
795 'wc-ajax' => '%%endpoint%%',
796 );
797
798 $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
799 $uri = $uri[0];
800
801 $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
802 }
803 }
804 }
805
806 return $endpoint_url;
807 }
808
809
810 /**
811 * Save checkout fields.
812 *
813 * @param int $order_id order id.
814 * @param array $posted posted data.
815 * @return void
816 */
817 function save_checkout_fields( $order_id, $posted ) {
818
819 if ( isset( $_POST['_wcf_checkout_id'] ) ) {
820
821 $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
822
823 update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
824
825 /*
826 Custom Field To Do
827 $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
828
829 if ( 'yes' === $custom_fields ) {
830
831 $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
832
833 foreach ( $billing_fields as $field => $data ) {
834
835 if ( isset( $data['custom'] ) && $data['custom'] ) {
836
837 if ( isset( $_POST[ $field ] ) ) {
838 update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
839 }
840 }
841 }
842
843 $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
844
845 foreach ( $shipping_fields as $field => $data ) {
846
847 if ( isset( $data['custom'] ) && $data['custom'] ) {
848
849 if ( isset( $_POST[ $field ] ) ) {
850 update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
851 }
852 }
853 }
854 }
855 */
856 if ( isset( $_POST['_wcf_flow_id'] ) ) {
857
858 $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
859
860 update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
861 }
862 }
863
864 }
865
866 /**
867 * Enable Logo In Header Of Checkout Page
868 *
869 * @return void
870 */
871 function enable_logo_in_header() {
872 global $post;
873
874 if ( _is_wcf_checkout_type() ) {
875 $checkout_id = $post->ID;
876 } else {
877 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
878 }
879
880 $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
881 $add_image_markup = '';
882
883 if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
884 $add_image_markup = '<div class="wcf-checkout-header-image">';
885 $add_image_markup .= '<img src="' . $header_logo_image . '" />';
886 $add_image_markup .= '</div>';
887 }
888
889 echo $add_image_markup;
890 }
891
892 /**
893 * Add text to the bootom of the checkout page.
894 *
895 * @return void
896 */
897 function show_cartflows_copyright_message() {
898 $output_string = '';
899
900 $output_string .= '<div class="wcf-footer-primary">';
901 $output_string .= '<div class="wcf-footer-content">';
902 $output_string .= '<p class="wcf-footer-message">';
903 $output_string .= 'Checkout powered by CartFlows';
904 $output_string .= '</p>';
905 $output_string .= '</div>';
906 $output_string .= '</div>';
907
908 echo $output_string;
909 }
910
911 /**
912 * Redirect users to our checkout if hidden param
913 *
914 * @param string $redirect redirect url.
915 * @param object $user user.
916 * @return string
917 */
918 function after_login_redirect( $redirect, $user ) {
919
920 if ( isset( $_POST['_wcf_checkout_id'] ) ) {
921
922 $checkout_id = intval( $_POST['_wcf_checkout_id'] );
923
924 $redirect = get_permalink( $checkout_id );
925 }
926
927 return $redirect;
928 }
929
930 /**
931 * Display coupon code field after review order fields.
932 */
933 function display_custom_coupon_field() {
934
935 $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
936 $show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
937
938 if ( ! ( $coupon_enabled && $show_coupon ) ) {
939 return;
940
941 }
942
943 ob_start();
944 ?>
945 <div class="wcf-custom-coupon-field">
946 <div class="wcf-coupon-col-1">
947 <span>
948 <input type="text" name="coupon_code" class="input-text wcf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
949 </span>
950 </div>
951 <div class="wcf-coupon-col-2">
952 <span>
953 <button type="button" class="button wcf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
954 </span>
955 </div>
956 </div>
957 <?php
958 echo ob_get_clean();
959 }
960
961 /**
962 * Apply filter to change class of remove coupon field.
963 *
964 * @param string $coupon coupon.
965 * @return string
966 */
967 function remove_coupon_text( $coupon ) {
968
969 $coupon = str_replace( 'woocommerce-remove-coupon', 'wcf-remove-coupon', $coupon );
970 return $coupon;
971
972 }
973 /**
974 * Apply filter to change the placeholder text of coupon field.
975 *
976 * @return string
977 */
978 function coupon_field_placeholder() {
979 return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
980 }
981
982 /**
983 * Apply filter to change the button text of coupon field.
984 *
985 * @return string
986 */
987 function coupon_button_text() {
988 return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
989 }
990
991 /**
992 * Apply coupon on submit of custom coupon form.
993 */
994 function apply_coupon() {
995
996 $response = '';
997
998 check_ajax_referer( 'wcf-apply-coupon', 'security' );
999 if ( ! empty( $_POST['coupon_code'] ) ) {
1000 $result = WC()->cart->add_discount( sanitize_text_field( $_POST['coupon_code'] ) );
1001 } else {
1002 wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' );
1003 }
1004
1005 $response = array(
1006 'status' => $result,
1007 'msg' => wc_print_notices( true ),
1008 );
1009
1010 echo json_encode( $response );
1011
1012 die();
1013 }
1014
1015
1016 /**
1017 * Added ajax nonce to localize variable.
1018 *
1019 * @param array $vars localize variables.
1020 */
1021 function add_localize_vars( $vars ) {
1022
1023 $vars['wcf_validate_coupon_nonce'] = wp_create_nonce( 'wcf-apply-coupon' );
1024
1025 $vars['wcf_validate_remove_coupon_nonce'] = wp_create_nonce( 'wcf-remove-coupon' );
1026
1027 $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1028
1029 return $vars;
1030 }
1031
1032 /**
1033 * Add custom class to the fields to change the UI to three column.
1034 *
1035 * @param array $fields fields.
1036 */
1037 function add_three_column_layout_fields( $fields ) {
1038
1039 if ( empty( $fields['billing']['billing_address_2'] ) ) {
1040
1041 if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1042 $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1043 }
1044 }
1045
1046 if ( ! empty( $fields['billing']['billing_company'] ) ) {
1047
1048 if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1049 $fields['billing']['billing_company']['class'][] = 'form-row-full';
1050 }
1051 }
1052
1053 if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1054
1055 if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1056 $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1057 }
1058 }
1059
1060 if ( ! empty( $fields['billing']['billing_country'] ) ) {
1061
1062 if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1063 $fields['billing']['billing_country']['class'][] = 'form-row-full';
1064 }
1065 }
1066
1067 if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1068
1069 if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1070 $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1071 }
1072 }
1073
1074 if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1075
1076 if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1077 $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1078 }
1079 }
1080
1081 if ( ! empty( $fields['billing']['billing_email'] ) ) {
1082
1083 if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1084 $fields['billing']['billing_email']['class'][] = 'form-row-full';
1085 }
1086 }
1087
1088 if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1089
1090 if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1091 $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1092 }
1093 }
1094
1095 if ( isset( $fields['billing']['billing_city'] ) &&
1096 isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1097
1098 $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1099 $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1100 $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1101 }
1102
1103 if ( isset( $fields['shipping']['shipping_city'] ) &&
1104 isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1105
1106 $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1107 $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1108 $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1109 }
1110
1111 return $fields;
1112 }
1113
1114 /**
1115 * Add opening dev
1116 *
1117 * @since 1.0.0
1118 */
1119 function order_wrap_div_start() {
1120
1121 echo "<div class='wcf-order-wrap'> ";
1122 }
1123
1124 /**
1125 * Add closing dev
1126 *
1127 * @since 1.0.0
1128 */
1129 function order_wrap_div_end() {
1130
1131 echo '</div> ';
1132 }
1133
1134 /**
1135 * Remove coupon.
1136 */
1137 function remove_coupon() {
1138
1139 check_ajax_referer( 'wcf-remove-coupon', 'security' );
1140 $coupon = isset( $_POST['coupon_code'] ) ? wc_clean( $_POST['coupon_code'] ) : false;
1141
1142 if ( empty( $coupon ) ) {
1143 echo "<div class='woocommerce-error'>Sorry there was a problem removing this coupon.";
1144 } else {
1145 WC()->cart->remove_coupon( $coupon );
1146 echo "<div class='woocommerce-error'>Coupon has been removed.</div>";
1147 }
1148 wc_print_notices();
1149 wp_die();
1150 }
1151
1152 }
1153
1154 /**
1155 * Kicking this off by calling 'get_instance()' method
1156 */
1157 Cartflows_Checkout_Markup::get_instance();
1158