PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.10
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.10
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.10, at modules/checkout/classes/class-cartflows-checkout-markup.php

1,112 lines 32.8 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_cf_woo_apply_coupon', array( $this, 'apply_coupon' ) );
64 add_action( 'wp_ajax_nopriv_cf_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 }
72
73 /**
74 * Display all WooCommerce notices.
75 *
76 * @since 1.1.5
77 */
78 function display_woo_notices() {
79
80 if ( null != WC()->session && function_exists( 'woocommerce_output_all_notices' ) ) {
81 woocommerce_output_all_notices();
82 }
83 }
84
85
86 /**
87 * Redirect from default to the global checkout page
88 *
89 * @since 1.0.0
90 */
91 function global_checkout_template_redirect() {
92
93 if ( ! is_checkout() ) {
94 return;
95 }
96
97 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
98 return;
99 }
100
101 // redirect only from any non HC checkout pages.
102 $order_pay_endpoint = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
103 $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
104
105 $common = Cartflows_Helper::get_common_settings();
106
107 $global_checkout = $common['global_checkout'];
108
109 if (
110 // ignore on order-pay.
111 false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
112 // ignore on TY page.
113 false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
114 ) {
115
116 if ( '' !== $global_checkout ) {
117
118 $link = get_permalink( $global_checkout );
119
120 if ( ! empty( $link ) ) {
121
122 wp_redirect( $link );
123 die();
124 }
125 }
126 }
127 }
128
129 /**
130 * Check for checkout flag
131 *
132 * @param bool $is_checkout is checkout.
133 *
134 * @return bool
135 */
136 function woo_checkout_flag( $is_checkout ) {
137
138 if ( ! is_admin() ) {
139
140 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
141
142 $is_checkout = true;
143 }
144 }
145
146 return $is_checkout;
147 }
148
149 /**
150 * Render checkout shortcode markup.
151 *
152 * @param array $atts attributes.
153 * @return string
154 */
155 function checkout_shortcode_markup( $atts ) {
156
157 if ( ! function_exists( 'wc_print_notices' ) ) {
158 return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
159 }
160
161 $atts = shortcode_atts(
162 array(
163 'id' => 0,
164 ),
165 $atts
166 );
167
168 $checkout_id = intval( $atts['id'] );
169
170 if ( empty( $checkout_id ) ) {
171
172 if ( ! _is_wcf_checkout_type() ) {
173
174 return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
175 }
176
177 global $post;
178
179 $checkout_id = intval( $post->ID );
180 }
181
182 $output = '';
183
184 ob_start();
185
186 do_action( 'cartflows_checkout_form_before', $checkout_id );
187
188 $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
189
190 $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
191
192 $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
193
194 if ( file_exists( $template_layout ) ) {
195 include $template_layout;
196 } else {
197 include $template_default;
198 }
199
200 $output .= ob_get_clean();
201
202 return $output;
203 }
204
205 /**
206 * Configure Cart Data.
207 *
208 * @since 1.0.0
209 *
210 * @return void
211 */
212 function preconfigured_cart_data() {
213
214 if ( is_admin() ) {
215 return;
216 }
217
218 global $post;
219
220 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
221
222 if ( wp_doing_ajax() ) {
223
224 return;
225 } else {
226
227 if ( _is_wcf_checkout_type() ) {
228 $checkout_id = $post->ID;
229 } else {
230 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
231 }
232
233 do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
234
235 $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
236
237 if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
238 $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
239 } else {
240 $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
241 }
242
243 if ( ! is_array( $products ) ) {
244
245 if ( 'dummy' === $products ) {
246
247 $args = array(
248 'posts_per_page' => 1,
249 'orderby' => 'rand',
250 'post_type' => 'product',
251 'meta_query' => array(
252 // Exclude out of stock products.
253 array(
254 'key' => '_stock_status',
255 'value' => 'outofstock',
256 'compare' => 'NOT IN',
257 ),
258 ),
259 'tax_query' => array(
260 array(
261 'taxonomy' => 'product_type',
262 'field' => 'slug',
263 'terms' => 'simple',
264 ),
265 ),
266 );
267
268 $random_product = get_posts( $args );
269
270 if ( isset( $random_product[0]->ID ) ) {
271 $products = array(
272 array(
273 'product' => $random_product[0]->ID,
274 ),
275 );
276 } else {
277 return;
278 }
279 } else {
280 return;
281 }
282 }
283
284 if ( is_array( $products ) && count( $products ) < 1 ) {
285
286 return;
287 }
288 /* Empty the current cart */
289 WC()->cart->empty_cart();
290
291 /* Set customer session if not set */
292 if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
293 WC()->session->set_customer_session_cookie( true );
294 }
295
296 $cart_product_count = 0;
297
298 foreach ( $products as $index => $data ) {
299
300 if ( ! isset( $data['product'] ) ) {
301 return;
302 }
303
304 if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
305 break;
306 }
307
308 $product_id = $data['product'];
309 $_product = wc_get_product( $product_id );
310
311 if ( ! empty( $_product ) ) {
312
313 $quantity = 1;
314
315 if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
316
317 if ( $_product->is_type( 'variable' ) ) {
318
319 $default_attributes = $_product->get_default_attributes();
320
321 if ( ! empty( $default_attributes ) ) {
322
323 foreach ( $_product->get_children() as $variation_id ) {
324
325 $single_variation = new WC_Product_Variation( $variation_id );
326
327 if ( $default_attributes == $single_variation->get_attributes() ) {
328 WC()->cart->add_to_cart( $variation_id, $quantity );
329 $cart_product_count++;
330 }
331 }
332 } else {
333
334 $product_childrens = $_product->get_children();
335
336 if ( isset( $product_childrens[0] ) ) {
337 WC()->cart->add_to_cart( $product_childrens[0], $quantity );
338 $cart_product_count++;
339 } else {
340 echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
341 }
342 }
343 } else {
344 WC()->cart->add_to_cart( $product_id, $quantity );
345 $cart_product_count++;
346 }
347 } else {
348
349 echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
350 // WC()->cart->add_to_cart( $product_id, $quantity );.
351 }
352 }
353 }
354
355 do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
356 do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
357 }
358 }
359 }
360
361 /**
362 * Load shortcode data.
363 *
364 * @return void
365 */
366 function shortcode_load_data() {
367
368 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
369
370 add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
371
372 add_action( 'wp_enqueue_scripts', array( $this, 'compatibility_scripts' ), 101 );
373
374 /* Show notices if cart has errors */
375 add_action( 'woocommerce_cart_has_errors', 'woocommerce_output_all_notices' );
376
377 add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
378
379 add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
380
381 // Outputting the hidden field in checkout page.
382 add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
383 add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
384
385 remove_all_actions( 'woocommerce_checkout_billing' );
386 remove_all_actions( 'woocommerce_checkout_shipping' );
387
388 // Hook in actions once.
389 add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
390 add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
391
392 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
393
394 add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
395
396 add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
397
398 global $post;
399
400 if ( _is_wcf_checkout_type() ) {
401 $checkout_id = $post->ID;
402 } else {
403 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
404 }
405
406 do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
407 }
408 }
409
410 /**
411 * Render checkout ID hidden field.
412 *
413 * @param array $checkout checkout session data.
414 * @return void
415 */
416 function checkout_shortcode_post_id( $checkout ) {
417
418 global $post;
419
420 if ( _is_wcf_checkout_type() ) {
421 $checkout_id = $post->ID;
422 } else {
423 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
424 }
425
426 $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
427
428 echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
429 echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
430 }
431
432 /**
433 * Load shortcode scripts.
434 *
435 * @return void
436 */
437 function shortcode_scripts() {
438
439 wp_enqueue_style( 'wcf-checkout-template', CARTFLOWS_URL . 'assets/css/checkout-template.css', '', CARTFLOWS_VER );
440 wp_style_add_data( 'wcf-checkout-template', 'rtl', 'replace' );
441
442 wp_enqueue_script(
443 'wcf-checkout-template',
444 CARTFLOWS_URL . 'assets/js/checkout-template.js',
445 array( 'jquery' ),
446 CARTFLOWS_VER,
447 true
448 );
449
450 do_action( 'cartflows_checkout_scripts' );
451
452 $style = $this->generate_style();
453
454 wp_add_inline_style( 'wcf-checkout-template', $style );
455
456 }
457
458 /**
459 * Load compatibility scripts.
460 *
461 * @return void
462 */
463 function compatibility_scripts() {
464
465 global $post;
466
467 if ( _is_wcf_checkout_type() ) {
468 $checkout_id = $post->ID;
469 } else {
470 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
471 }
472
473 // Add DIVI Compatibility css if DIVI theme is enabled.
474 if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ||
475 Cartflows_Compatibility::get_instance()->is_divi_builder_enabled( $checkout_id )
476 ) {
477 wp_enqueue_style( 'wcf-checkout-template-divi', CARTFLOWS_URL . 'assets/css/checkout-template-divi.css', '', CARTFLOWS_VER );
478 wp_style_add_data( 'wcf-checkout-template-divi', 'rtl', 'replace' );
479 }
480
481 // Add Flatsome Compatibility css if Flatsome theme is enabled.
482 if ( Cartflows_Compatibility::get_instance()->is_flatsome_enabled() ) {
483 wp_enqueue_style( 'wcf-checkout-template-flatsome', CARTFLOWS_URL . 'assets/css/checkout-template-flatsome.css', '', CARTFLOWS_VER );
484 wp_style_add_data( 'wcf-checkout-template-flatsome', 'rtl', 'replace' );
485 }
486
487 // Add The7 Compatibility css if The7 theme is enabled.
488 if ( Cartflows_Compatibility::get_instance()->is_the_seven_enabled() ) {
489 wp_enqueue_style( 'wcf-checkout-template-the-seven', CARTFLOWS_URL . 'assets/css/checkout-template-the-seven.css', '', CARTFLOWS_VER );
490 wp_style_add_data( 'wcf-checkout-template-the-seven', 'rtl', 'replace' );
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-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
774 return $output;
775 }
776
777 /**
778 * Get ajax end points.
779 *
780 * @param string $endpoint_url end point URL.
781 * @return string
782 */
783 function get_ajax_endpoint( $endpoint_url ) {
784
785 global $post;
786
787 if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
788
789 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
790
791 if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
792
793 $query_args = array(
794 'wc-ajax' => '%%endpoint%%',
795 );
796
797 $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
798 $uri = $uri[0];
799
800 $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
801 }
802 }
803 }
804
805 return $endpoint_url;
806 }
807
808
809 /**
810 * Save checkout fields.
811 *
812 * @param int $order_id order id.
813 * @param array $posted posted data.
814 * @return void
815 */
816 function save_checkout_fields( $order_id, $posted ) {
817
818 if ( isset( $_POST['_wcf_checkout_id'] ) ) {
819
820 $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
821
822 update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
823
824 /*
825 Custom Field To Do
826 $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
827
828 if ( 'yes' === $custom_fields ) {
829
830 $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
831
832 foreach ( $billing_fields as $field => $data ) {
833
834 if ( isset( $data['custom'] ) && $data['custom'] ) {
835
836 if ( isset( $_POST[ $field ] ) ) {
837 update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
838 }
839 }
840 }
841
842 $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
843
844 foreach ( $shipping_fields as $field => $data ) {
845
846 if ( isset( $data['custom'] ) && $data['custom'] ) {
847
848 if ( isset( $_POST[ $field ] ) ) {
849 update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
850 }
851 }
852 }
853 }
854 */
855 if ( isset( $_POST['_wcf_flow_id'] ) ) {
856
857 $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
858
859 update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
860 }
861 }
862
863 }
864
865 /**
866 * Enable Logo In Header Of Checkout Page
867 *
868 * @return void
869 */
870 function enable_logo_in_header() {
871 global $post;
872
873 if ( _is_wcf_checkout_type() ) {
874 $checkout_id = $post->ID;
875 } else {
876 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
877 }
878
879 $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
880 $add_image_markup = '';
881
882 if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
883 $add_image_markup = '<div class="wcf-checkout-header-image">';
884 $add_image_markup .= '<img src="' . $header_logo_image . '" />';
885 $add_image_markup .= '</div>';
886 }
887
888 echo $add_image_markup;
889 }
890
891 /**
892 * Add text to the bootom of the checkout page.
893 *
894 * @return void
895 */
896 function show_cartflows_copyright_message() {
897 $output_string = '';
898
899 $output_string .= '<div class="wcf-footer-primary">';
900 $output_string .= '<div class="wcf-footer-content">';
901 $output_string .= '<p class="wcf-footer-message">';
902 $output_string .= 'Checkout powered by CartFlows';
903 $output_string .= '</p>';
904 $output_string .= '</div>';
905 $output_string .= '</div>';
906
907 echo $output_string;
908 }
909
910 /**
911 * Redirect users to our checkout if hidden param
912 *
913 * @param string $redirect redirect url.
914 * @param object $user user.
915 * @return string
916 */
917 function after_login_redirect( $redirect, $user ) {
918
919 if ( isset( $_POST['_wcf_checkout_id'] ) ) {
920
921 $checkout_id = intval( $_POST['_wcf_checkout_id'] );
922
923 $redirect = get_permalink( $checkout_id );
924 }
925
926 return $redirect;
927 }
928
929 /**
930 * Display coupon code field after review order fields.
931 */
932 function display_custom_coupon_field() {
933
934 $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
935 $cf_show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
936
937 if ( ! ( $coupon_enabled && $cf_show_coupon ) ) {
938 return;
939
940 }
941
942 ob_start();
943 ?>
944 <div class="wcf-custom-coupon-field">
945 <div class="wcf-coupon-col-1">
946 <span>
947 <input type="text" name="coupon_code" class="input-text cf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
948 </span>
949 </div>
950 <div class="wcf-coupon-col-2">
951 <span>
952 <button type="button" class="button cf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
953 </span>
954 </div>
955 </div>
956 <?php
957 echo ob_get_clean();
958 }
959
960 /**
961 * Apply filter to change the placeholder text of coupon field.
962 *
963 * @return string
964 */
965 function coupon_field_placeholder() {
966 return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
967 }
968
969 /**
970 * Apply filter to change the button text of coupon field.
971 *
972 * @return string
973 */
974 function coupon_button_text() {
975 return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
976 }
977
978 /**
979 * Apply coupon on submit of custom coupon form.
980 */
981 function apply_coupon() {
982
983 check_ajax_referer( 'cf-apply-coupon', 'security' );
984
985 $result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
986
987 echo json_encode( $result );
988 die();
989 }
990
991 /**
992 * Added ajax nonce to localize variable.
993 *
994 * @param array $vars localize variables.
995 */
996 function add_localize_vars( $vars ) {
997
998 $vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
999
1000 $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1001
1002 return $vars;
1003 }
1004
1005 /**
1006 * Add custom class to the fields to change the UI to three column.
1007 *
1008 * @param array $fields fields.
1009 */
1010 function add_three_column_layout_fields( $fields ) {
1011
1012 if ( empty( $fields['billing']['billing_address_2'] ) ) {
1013
1014 if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1015 $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1016 }
1017 }
1018
1019 if ( ! empty( $fields['billing']['billing_company'] ) ) {
1020
1021 if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1022 $fields['billing']['billing_company']['class'][] = 'form-row-full';
1023 }
1024 }
1025
1026 if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1027
1028 if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1029 $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1030 }
1031 }
1032
1033 if ( ! empty( $fields['billing']['billing_country'] ) ) {
1034
1035 if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1036 $fields['billing']['billing_country']['class'][] = 'form-row-full';
1037 }
1038 }
1039
1040 if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1041
1042 if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1043 $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1044 }
1045 }
1046
1047 if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1048
1049 if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1050 $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1051 }
1052 }
1053
1054 if ( ! empty( $fields['billing']['billing_email'] ) ) {
1055
1056 if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1057 $fields['billing']['billing_email']['class'][] = 'form-row-full';
1058 }
1059 }
1060
1061 if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1062
1063 if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1064 $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1065 }
1066 }
1067
1068 if ( isset( $fields['billing']['billing_city'] ) &&
1069 isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1070
1071 $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1072 $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1073 $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1074 }
1075
1076 if ( isset( $fields['shipping']['shipping_city'] ) &&
1077 isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1078
1079 $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1080 $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1081 $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1082 }
1083
1084 return $fields;
1085 }
1086
1087 /**
1088 * Add opening dev
1089 *
1090 * @since 1.0.0
1091 */
1092 function order_wrap_div_start() {
1093
1094 echo "<div class='wcf-order-wrap'> ";
1095 }
1096
1097 /**
1098 * Add closing dev
1099 *
1100 * @since 1.0.0
1101 */
1102 function order_wrap_div_end() {
1103
1104 echo '</div> ';
1105 }
1106 }
1107
1108 /**
1109 * Kicking this off by calling 'get_instance()' method
1110 */
1111 Cartflows_Checkout_Markup::get_instance();
1112