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

1,113 lines 33.9 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-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 $cf_show_coupon = apply_filters( 'cartflows_show_coupon_field', true );
937
938 if ( ! ( $coupon_enabled && $cf_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 cf-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 cf-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 the placeholder text of coupon field.
963 *
964 * @return string
965 */
966 function coupon_field_placeholder() {
967 return apply_filters( 'cartflows_coupon_field_placeholder', __( 'Coupon Code', 'cartflows' ) );
968 }
969
970 /**
971 * Apply filter to change the button text of coupon field.
972 *
973 * @return string
974 */
975 function coupon_button_text() {
976 return apply_filters( 'cartflows_coupon_button_text', __( 'Apply', 'cartflows' ) );
977 }
978
979 /**
980 * Apply coupon on submit of custom coupon form.
981 */
982 function apply_coupon() {
983
984 check_ajax_referer( 'cf-apply-coupon', 'security' );
985
986 $result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
987
988 echo json_encode( $result );
989 die();
990 }
991
992 /**
993 * Added ajax nonce to localize variable.
994 *
995 * @param array $vars localize variables.
996 */
997 function add_localize_vars( $vars ) {
998
999 $vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
1000
1001 $vars['allow_persistance'] = apply_filters( 'cartflows_allow_persistace', 'yes' );
1002
1003 return $vars;
1004 }
1005
1006 /**
1007 * Add custom class to the fields to change the UI to three column.
1008 *
1009 * @param array $fields fields.
1010 */
1011 function add_three_column_layout_fields( $fields ) {
1012
1013 if ( empty( $fields['billing']['billing_address_2'] ) ) {
1014
1015 if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
1016 $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
1017 }
1018 }
1019
1020 if ( ! empty( $fields['billing']['billing_company'] ) ) {
1021
1022 if ( isset( $fields['billing']['billing_company'] ) && is_array( $fields['billing']['billing_company'] ) ) {
1023 $fields['billing']['billing_company']['class'][] = 'form-row-full';
1024 }
1025 }
1026
1027 if ( ! empty( $fields['shipping']['shipping_company'] ) ) {
1028
1029 if ( isset( $fields['shipping']['shipping_company'] ) && is_array( $fields['shipping']['shipping_company'] ) ) {
1030 $fields['shipping']['shipping_company']['class'][] = 'form-row-full';
1031 }
1032 }
1033
1034 if ( ! empty( $fields['billing']['billing_country'] ) ) {
1035
1036 if ( isset( $fields['billing']['billing_country'] ) && is_array( $fields['billing']['billing_country'] ) ) {
1037 $fields['billing']['billing_country']['class'][] = 'form-row-full';
1038 }
1039 }
1040
1041 if ( ! empty( $fields['shipping']['shipping_country'] ) ) {
1042
1043 if ( isset( $fields['shipping']['shipping_country'] ) && is_array( $fields['shipping']['shipping_country'] ) ) {
1044 $fields['shipping']['shipping_country']['class'][] = 'form-row-full';
1045 }
1046 }
1047
1048 if ( ! empty( $fields['billing']['billing_phone'] ) ) {
1049
1050 if ( isset( $fields['billing']['billing_phone'] ) && is_array( $fields['billing']['billing_phone'] ) ) {
1051 $fields['billing']['billing_phone']['class'][] = 'form-row-full';
1052 }
1053 }
1054
1055 if ( ! empty( $fields['billing']['billing_email'] ) ) {
1056
1057 if ( isset( $fields['billing']['billing_email'] ) && is_array( $fields['billing']['billing_email'] ) ) {
1058 $fields['billing']['billing_email']['class'][] = 'form-row-full';
1059 }
1060 }
1061
1062 if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
1063
1064 if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
1065 $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
1066 }
1067 }
1068
1069 if ( isset( $fields['billing']['billing_city'] ) &&
1070 isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
1071
1072 $fields['billing']['billing_city']['class'][] = 'wcf-column-33';
1073 $fields['billing']['billing_state']['class'][] = 'wcf-column-33';
1074 $fields['billing']['billing_postcode']['class'][] = 'wcf-column-33';
1075 }
1076
1077 if ( isset( $fields['shipping']['shipping_city'] ) &&
1078 isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
1079
1080 $fields['shipping']['shipping_city']['class'][] = 'wcf-column-33';
1081 $fields['shipping']['shipping_state']['class'][] = 'wcf-column-33';
1082 $fields['shipping']['shipping_postcode']['class'][] = 'wcf-column-33';
1083 }
1084
1085 return $fields;
1086 }
1087
1088 /**
1089 * Add opening dev
1090 *
1091 * @since 1.0.0
1092 */
1093 function order_wrap_div_start() {
1094
1095 echo "<div class='wcf-order-wrap'> ";
1096 }
1097
1098 /**
1099 * Add closing dev
1100 *
1101 * @since 1.0.0
1102 */
1103 function order_wrap_div_end() {
1104
1105 echo '</div> ';
1106 }
1107 }
1108
1109 /**
1110 * Kicking this off by calling 'get_instance()' method
1111 */
1112 Cartflows_Checkout_Markup::get_instance();
1113