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

988 lines 29.5 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', 'woocommerce_output_all_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 add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'order_wrap_div_start' ), 99 );
72
73 add_action( 'woocommerce_checkout_after_order_review', array( $this, 'order_wrap_div_end' ), 99 );
74 }
75
76
77 /**
78 * Redirect from default to the global checkout page
79 *
80 * @since 1.0.0
81 */
82 function global_checkout_template_redirect() {
83
84 if ( ! is_checkout() ) {
85 return;
86 }
87
88 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
89 return;
90 }
91
92 // redirect only from any non HC checkout pages.
93 $order_pay_endpoint = get_option( 'woocommerce_checkout_order_pay_endpoint', 'order-pay' );
94 $order_received_endpoint = get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' );
95
96 $common = Cartflows_Helper::get_common_settings();
97
98 $global_checkout = $common['global_checkout'];
99
100 if (
101 // ignore on order-pay.
102 false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_pay_endpoint . '/' ) &&
103 // ignore on TY page.
104 false === mb_strpos( $_SERVER['REQUEST_URI'], '/' . $order_received_endpoint . '/' )
105 ) {
106
107 if ( '' !== $global_checkout ) {
108
109 $link = get_permalink( $global_checkout );
110
111 if ( ! empty( $link ) ) {
112
113 wp_redirect( $link );
114 die();
115 }
116 }
117 }
118 }
119
120 /**
121 * Check for checkout flag
122 *
123 * @param bool $is_checkout is checkout.
124 *
125 * @return bool
126 */
127 function woo_checkout_flag( $is_checkout ) {
128
129 if ( ! is_admin() ) {
130
131 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
132
133 $is_checkout = true;
134 }
135 }
136
137 return $is_checkout;
138 }
139
140 /**
141 * Render checkout shortcode markup.
142 *
143 * @param array $atts attributes.
144 * @return string
145 */
146 function checkout_shortcode_markup( $atts ) {
147
148 if ( ! function_exists( 'wc_print_notices' ) ) {
149 return '<p class="woocommerce-notice">' . __( 'WooCommerce functions not exists. If you are in iframe, please reload the iframe', 'cartflows' ) . '</p>';
150 }
151
152 $atts = shortcode_atts(
153 array(
154 'id' => 0,
155 ),
156 $atts
157 );
158
159 $checkout_id = intval( $atts['id'] );
160
161 if ( empty( $checkout_id ) ) {
162
163 if ( ! _is_wcf_checkout_type() ) {
164
165 return '<h4>' . __( 'Checkout ID not found', 'cartflows' ) . '</h4>';
166 }
167
168 global $post;
169
170 $checkout_id = intval( $post->ID );
171 }
172
173 $output = '';
174
175 ob_start();
176
177 do_action( 'cartflows_checkout_form_before', $checkout_id );
178
179 $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
180
181 $template_default = CARTFLOWS_CHECKOUT_DIR . 'templates/embed/checkout-template-simple.php';
182
183 $template_layout = apply_filters( 'cartflows_checkout_layout_template', $checkout_layout );
184
185 if ( file_exists( $template_layout ) ) {
186 include $template_layout;
187 } else {
188 include $template_default;
189 }
190
191 $output .= ob_get_clean();
192
193 return $output;
194 }
195
196 /**
197 * Configure Cart Data.
198 *
199 * @since 1.0.0
200 *
201 * @return void
202 */
203 function preconfigured_cart_data() {
204
205 if ( is_admin() ) {
206 return;
207 }
208
209 global $post;
210
211 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
212
213 if ( wp_doing_ajax() ) {
214
215 return;
216 } else {
217
218 if ( _is_wcf_checkout_type() ) {
219 $checkout_id = $post->ID;
220 } else {
221 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
222 }
223
224 do_action( 'cartflows_checkout_before_configure_cart', $checkout_id );
225
226 $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
227
228 if ( wcf()->flow->is_flow_testmode( $flow_id ) ) {
229 $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products', 'dummy' );
230 } else {
231 $products = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-products' );
232 }
233
234 if ( ! is_array( $products ) ) {
235
236 if ( 'dummy' === $products ) {
237
238 $args = array(
239 'posts_per_page' => 1,
240 'orderby' => 'rand',
241 'post_type' => 'product',
242 'meta_query' => array(
243 // Exclude out of stock products.
244 array(
245 'key' => '_stock_status',
246 'value' => 'outofstock',
247 'compare' => 'NOT IN',
248 ),
249 ),
250 'tax_query' => array(
251 array(
252 'taxonomy' => 'product_type',
253 'field' => 'slug',
254 'terms' => 'simple',
255 ),
256 ),
257 );
258
259 $random_product = get_posts( $args );
260
261 if ( isset( $random_product[0]->ID ) ) {
262 $products = array(
263 array(
264 'product' => $random_product[0]->ID,
265 ),
266 );
267 } else {
268 return;
269 }
270 } else {
271 return;
272 }
273 }
274
275 if ( is_array( $products ) && count( $products ) < 1 ) {
276
277 return;
278 }
279 /* Empty the current cart */
280 WC()->cart->empty_cart();
281
282 /* Set customer session if not set */
283 if ( ! is_user_logged_in() && WC()->cart->is_empty() ) {
284 WC()->session->set_customer_session_cookie( true );
285 }
286
287 $cart_product_count = 0;
288
289 foreach ( $products as $index => $data ) {
290
291 if ( ! isset( $data['product'] ) ) {
292 return;
293 }
294
295 if ( apply_filters( 'cartflows_skip_other_products', false, $cart_product_count ) ) {
296 return;
297 }
298
299 $product_id = $data['product'];
300 $_product = wc_get_product( $product_id );
301
302 if ( ! empty( $_product ) ) {
303
304 $quantity = 1;
305
306 if ( ! $_product->is_type( 'grouped' ) && ! $_product->is_type( 'external' ) ) {
307
308 if ( $_product->is_type( 'variable' ) ) {
309
310 $default_attributes = $_product->get_default_attributes();
311
312 if ( ! empty( $default_attributes ) ) {
313
314 foreach ( $_product->get_children() as $variation_id ) {
315
316 $single_variation = new WC_Product_Variation( $variation_id );
317
318 if ( $default_attributes == $single_variation->get_attributes() ) {
319 WC()->cart->add_to_cart( $variation_id, $quantity );
320 $cart_product_count++;
321 }
322 }
323 } else {
324
325 $product_childrens = $_product->get_children();
326
327 if ( isset( $product_childrens[0] ) ) {
328 WC()->cart->add_to_cart( $product_childrens[0], $quantity );
329 $cart_product_count++;
330 } else {
331 echo '<p>' . __( 'Variations Not set', 'cartflows' ) . '</p>';
332 }
333 }
334 } else {
335 WC()->cart->add_to_cart( $product_id, $quantity );
336 $cart_product_count++;
337 }
338 } else {
339
340 echo '<p>' . __( 'This product can\'t be purcahsed', 'cartflows' ) . '</p>';
341 // WC()->cart->add_to_cart( $product_id, $quantity );.
342 }
343 }
344 }
345
346 do_action( 'cartflows_checkout_aftet_configure_cart', $checkout_id );
347 do_action( 'cartflows_checkout_after_configure_cart', $checkout_id );
348 }
349 }
350 }
351
352 /**
353 * Load shortcode data.
354 *
355 * @return void
356 */
357 function shortcode_load_data() {
358
359 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
360
361 add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_scripts' ), 21 );
362
363 // Outputting the hidden field in checkout page.
364 add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_shortcode_post_id' ), 99 );
365 add_action( 'woocommerce_login_form_end', array( $this, 'checkout_shortcode_post_id' ), 99 );
366
367 remove_all_actions( 'woocommerce_checkout_billing' );
368 remove_all_actions( 'woocommerce_checkout_shipping' );
369
370 // Hook in actions once.
371 add_action( 'woocommerce_checkout_billing', array( WC()->checkout, 'checkout_form_billing' ) );
372 add_action( 'woocommerce_checkout_shipping', array( WC()->checkout, 'checkout_form_shipping' ) );
373
374 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
375
376 add_action( 'woocommerce_checkout_order_review', array( $this, 'display_custom_coupon_field' ) );
377
378 add_filter( 'woocommerce_checkout_fields', array( $this, 'add_three_column_layout_fields' ) );
379
380 global $post;
381
382 if ( _is_wcf_checkout_type() ) {
383 $checkout_id = $post->ID;
384 } else {
385 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
386 }
387
388 do_action( 'cartflows_checkout_before_shortcode', $checkout_id );
389 }
390 }
391
392 /**
393 * Render checkout ID hidden field.
394 *
395 * @param array $checkout checkout session data.
396 * @return void
397 */
398 function checkout_shortcode_post_id( $checkout ) {
399
400 global $post;
401
402 if ( _is_wcf_checkout_type() ) {
403 $checkout_id = $post->ID;
404 } else {
405 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
406 }
407
408 $flow_id = get_post_meta( $checkout_id, 'wcf-flow-id', true );
409
410 echo '<input type="hidden" class="input-hidden _wcf_flow_id" name="_wcf_flow_id" value="' . intval( $flow_id ) . '">';
411 echo '<input type="hidden" class="input-hidden _wcf_checkout_id" name="_wcf_checkout_id" value="' . intval( $checkout_id ) . '">';
412 }
413
414 /**
415 * Load shortcode scripts.
416 *
417 * @return void
418 */
419 function shortcode_scripts() {
420
421 wp_enqueue_style( 'wcf-checkout-template', CARTFLOWS_URL . 'assets/css/checkout-template.css', '', CARTFLOWS_VER );
422 wp_style_add_data( 'wcf-checkout-template', 'rtl', 'replace' );
423
424 if ( Cartflows_Compatibility::get_instance()->is_divi_enabled() ) {
425 wp_enqueue_style( 'wcf-checkout-template-divi', CARTFLOWS_URL . 'assets/css/checkout-template-divi.css', '', CARTFLOWS_VER );
426 wp_style_add_data( 'wcf-checkout-template-divi', 'rtl', 'replace' );
427 }
428
429 wp_enqueue_script(
430 'wcf-checkout-template',
431 CARTFLOWS_URL . 'assets/js/checkout-template.js',
432 array( 'jquery' ),
433 CARTFLOWS_VER,
434 true
435 );
436
437 do_action( 'cartflows_checkout_scripts' );
438
439 $style = $this->generate_style();
440
441 wp_add_inline_style( 'wcf-checkout-template', $style );
442
443 }
444
445
446 /**
447 * Generate styles.
448 *
449 * @return string
450 */
451 function generate_style() {
452
453 global $post;
454
455 if ( _is_wcf_checkout_type() ) {
456 $checkout_id = $post->ID;
457 } else {
458 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
459 }
460
461 CartFlows_Font_Families::render_fonts( $checkout_id );
462
463 $primary_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-primary-color' );
464
465 $base_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-family' );
466
467 $header_logo_width = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-width' );
468
469 /*$base_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-base-font-weight' );*/
470
471 $field_tb_padding = '';
472 $field_lr_padding = '';
473
474 $field_heading_color = '';
475 $field_color = '';
476 $field_bg_color = '';
477 $field_border_color = '';
478 $field_label_color = '';
479 $submit_tb_padding = '';
480 $submit_lr_padding = '';
481 $hl_bg_color = '';
482 $field_input_size = '';
483 $box_border_color = '';
484 $section_bg_color = '';
485 $submit_button_height = '';
486 $submit_color = '';
487 $submit_bg_color = $primary_color;
488 $submit_border_color = $primary_color;
489
490 $submit_hover_color = '';
491 $submit_bg_hover_color = $primary_color;
492 $submit_border_hover_color = $primary_color;
493
494 $section_heading_color = '';
495
496 $is_advance_option = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-advance-options-fields' );
497
498 $button_font_family = '';
499 $button_font_weight = '';
500 $input_font_family = '';
501 $input_font_weight = '';
502 $heading_font_family = '';
503 $heading_font_weight = '';
504 $base_font_family = $base_font_family;
505 /*$base_font_weight = $base_font_weight;*/
506
507 if ( 'yes' == $is_advance_option ) {
508
509 /**
510 * Get Font Family and Font Weight weight values
511 */
512 $section_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-section-bg-color' );
513
514 $heading_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-family' );
515 $heading_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-font-weight' );
516 $section_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-heading-color' );
517 $button_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-family' );
518 $button_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-button-font-weight' );
519 $input_font_family = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-family' );
520 $input_font_weight = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-font-weight' );
521 $field_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-tb-padding' );
522 $field_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-lr-padding' );
523 $field_input_size = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-field-size' );
524
525 $field_heading_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-heading-color' );
526
527 $field_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-color' );
528
529 $field_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-bg-color' );
530
531 $field_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-border-color' );
532
533 $field_label_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-field-label-color' );
534
535 $submit_tb_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-tb-padding' );
536
537 $submit_lr_padding = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-lr-padding' );
538
539 $submit_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-color' );
540
541 $submit_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-color', $primary_color );
542
543 $submit_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-color', $primary_color );
544
545 $submit_border_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-border-hover-color', $primary_color );
546
547 $submit_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-hover-color' );
548
549 $submit_bg_hover_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-submit-bg-hover-color', $primary_color );
550
551 $hl_bg_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-hl-bg-color' );
552
553 $box_border_color = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-box-border-color' );
554
555 $submit_button_height = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-input-button-size' );
556
557 /**
558 * Get font values
559 */
560
561 if ( 'custom' == $submit_button_height ) {
562 $submit_button_height = '38px';
563 }
564
565 if ( 'custom' == $field_input_size ) {
566 $field_input_size = '38px';
567 }
568 }
569
570 $output = "
571 .wcf-embed-checkout-form .wcf-checkout-header-image img{
572 width: {$header_logo_width}px;
573 }
574 .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:checked:after,
575 .wcf-embed-checkout-form .woocommerce .woocommerce-shipping-fields [type='checkbox']:not(:checked):after,
576 .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label:after,
577 .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label:after {
578 background: {$primary_color};
579 }
580
581 .wcf-embed-checkout-form .woocommerce-checkout label{
582 color: {$field_label_color};
583 }
584 .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box{
585 background-color: {$hl_bg_color};
586 font-family: {$input_font_family};
587 font-weight: {$input_font_weight};
588 }
589
590 .wcf-embed-checkout-form #add_payment_method #payment div.payment_box::before,
591 .wcf-embed-checkout-form .woocommerce-cart #payment div.payment_box::before,
592 .wcf-embed-checkout-form .woocommerce-checkout #payment div.payment_box::before
593 {
594 border-color: {$hl_bg_color};
595 border-right-color: transparent;
596 border-left-color: transparent;
597 border-top-color: transparent;
598 position: absolute;
599 }
600
601 .wcf-embed-checkout-form .woocommerce #payment [type='radio']:checked + label,
602 .wcf-embed-checkout-form .woocommerce #payment [type='radio']:not(:checked) + label{
603 font-family: {$input_font_family};
604 font-weight: {$input_font_weight};
605 }
606
607 .wcf-embed-checkout-form #order_review .wcf-custom-coupon-field input[type='text'],
608 .wcf-embed-checkout-form .woocommerce form .form-row input.input-text,
609 .wcf-embed-checkout-form .woocommerce form .form-row textarea,
610 .wcf-embed-checkout-form .select2-container--default .select2-selection--single {
611 color: {$field_color};
612 background: {$field_bg_color};
613 border-color: {$field_border_color};
614 padding-top: {$field_tb_padding}px;
615 padding-bottom: {$field_tb_padding}px;
616 padding-left: {$field_lr_padding}px;
617 padding-right: {$field_lr_padding}px;
618 min-height: {$field_input_size};
619 font-family: {$input_font_family};
620 font-weight: {$input_font_weight};
621 }
622
623 .wcf-embed-checkout-form .woocommerce .col2-set .col-1,
624 .wcf-embed-checkout-form .woocommerce .col2-set .col-2,
625 .wcf-embed-checkout-form .woocommerce-checkout .shop_table,
626 .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading,
627 .wcf-embed-checkout-form .woocommerce-checkout #payment,
628 .wcf-embed-checkout-form .woocommerce form.checkout_coupon
629 {
630 background-color: {$section_bg_color};
631 border-color: {$box_border_color};
632 font-family: {$input_font_family};
633 font-weight: {$input_font_weight};
634 }
635
636 .woocommerce table.shop_table th{
637 color: {$field_label_color};
638 }
639 .wcf-embed-checkout-form .woocommerce .woocommerce-info,
640 .wcf-embed-checkout-form .woocommerce-message{
641 border-top-color: {$primary_color};
642 background-color: {$hl_bg_color};
643 }
644 .wcf-embed-checkout-form .woocommerce a{
645 color: {$primary_color};
646 }
647 .wcf-embed-checkout-form .select2-container--default .select2-selection--single .select2-selection__rendered {
648 color: {$field_color};
649 }
650 .wcf-embed-checkout-form ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
651 color: {$field_color};
652 }
653 .wcf-embed-checkout-form ::-moz-placeholder { /* Firefox 19+ */
654 color: {$field_color};
655 }
656 .wcf-embed-checkout-form :-ms-input-placeholder { /* IE 10+ */
657 color: {$field_color};
658 }
659 .wcf-embed-checkout-form :-moz-placeholder { /* Firefox 18- */
660 color: {$field_color};
661 }
662 .wcf-embed-checkout-form .woocommerce form p.form-row label {
663 color: {$field_label_color};
664 font-family: {$input_font_family};
665 font-weight: {$input_font_weight};
666 }
667 .wcf-embed-checkout-form .woocommerce #order_review button {
668 color: {$submit_color};
669 background: {$submit_bg_color};
670 padding-top: {$submit_tb_padding}px;
671 padding-bottom: {$submit_tb_padding}px;
672 padding-left: {$submit_lr_padding}px;
673 padding-right: {$submit_lr_padding}px;
674 border-color: {$submit_border_color};
675 min-height: {$submit_button_height};
676 font-family: {$button_font_family};
677 font-weight: {$button_font_weight};
678 }
679 .wcf-embed-checkout-form .woocommerce-checkout form.woocommerce-form-login .button,
680 .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button{
681 background: {$submit_bg_color};
682 border: 1px {$submit_border_color} solid;
683 color: {$submit_color};
684 min-height: {$submit_button_height};
685 font-family: {$button_font_family};
686 font-weight: {$button_font_weight};
687 }
688 .wcf-embed-checkout-form .woocommerce-checkout form.login .button:hover,
689 .wcf-embed-checkout-form .woocommerce-checkout form.checkout_coupon .button:hover,
690 .wcf-embed-checkout-form .woocommerce #payment #place_order:hover,
691 .wcf-embed-checkout-form .woocommerce #order_review button.wcf-btn-small:hover{
692 color: {$submit_hover_color};
693 background-color: {$submit_bg_hover_color};
694 border-color: {$submit_border_hover_color};
695 }
696 .wcf-embed-checkout-form .woocommerce h3,
697 .wcf-embed-checkout-form .woocommerce h3 span,
698 .wcf-embed-checkout-form .woocommerce-checkout #order_review_heading{
699 color: {$section_heading_color};
700 font-family: {$heading_font_family};
701 font-weight: {$heading_font_weight};
702 }
703 .wcf-embed-checkout-form .woocommerce-info::before,
704 .wcf-embed-checkout-form .woocommerce-message::before{
705 color: {$primary_color};
706 }
707 .wcf-embed-checkout-form{
708 font-family: {$base_font_family};
709 }";
710
711 return $output;
712 }
713
714 /**
715 * Get ajax end points.
716 *
717 * @param string $endpoint_url end point URL.
718 * @return string
719 */
720 function get_ajax_endpoint( $endpoint_url ) {
721
722 global $post;
723
724 if ( ! empty( $post ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
725
726 if ( _is_wcf_checkout_type() || _is_wcf_checkout_shortcode() ) {
727
728 if ( mb_strpos( $endpoint_url, 'checkout' ) === false ) {
729
730 $query_args = array(
731 'wc-ajax' => '%%endpoint%%',
732 );
733
734 $uri = explode( '?', $_SERVER['REQUEST_URI'], 2 );
735 $uri = $uri[0];
736
737 $endpoint_url = esc_url( add_query_arg( $query_args, $uri ) );
738 }
739 }
740 }
741
742 return $endpoint_url;
743 }
744
745
746 /**
747 * Save checkout fields.
748 *
749 * @param int $order_id order id.
750 * @param array $posted posted data.
751 * @return void
752 */
753 function save_checkout_fields( $order_id, $posted ) {
754
755 if ( isset( $_POST['_wcf_checkout_id'] ) ) {
756
757 $checkout_id = wc_clean( $_POST['_wcf_checkout_id'] );
758
759 update_post_meta( $order_id, '_wcf_checkout_id', $checkout_id );
760
761 /*
762 Custom Field To Do
763 $custom_fields = get_post_meta( $checkout_id, 'wcf-custom-checkout-fields', true );
764
765 if ( 'yes' === $custom_fields ) {
766
767 $billing_fields = get_post_meta( $checkout_id, 'wcf_fields_billing', true );
768
769 foreach ( $billing_fields as $field => $data ) {
770
771 if ( isset( $data['custom'] ) && $data['custom'] ) {
772
773 if ( isset( $_POST[ $field ] ) ) {
774 update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
775 }
776 }
777 }
778
779 $shipping_fields = get_post_meta( $checkout_id, 'wcf_fields_shipping', true );
780
781 foreach ( $shipping_fields as $field => $data ) {
782
783 if ( isset( $data['custom'] ) && $data['custom'] ) {
784
785 if ( isset( $_POST[ $field ] ) ) {
786 update_post_meta( $order_id, $field, wc_clean( $_POST[ $field ] ) );
787 }
788 }
789 }
790 }
791 */
792 if ( isset( $_POST['_wcf_flow_id'] ) ) {
793
794 $checkout_id = wc_clean( $_POST['_wcf_flow_id'] );
795
796 update_post_meta( $order_id, '_wcf_flow_id', $checkout_id );
797 }
798 }
799
800 }
801
802 /**
803 * Enable Logo In Header Of Checkout Page
804 *
805 * @return void
806 */
807 function enable_logo_in_header() {
808 global $post;
809
810 if ( _is_wcf_checkout_type() ) {
811 $checkout_id = $post->ID;
812 } else {
813 $checkout_id = _get_wcf_checkout_id_from_shortcode( $post->post_content );
814 }
815
816 $header_logo_image = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-header-logo-image' );
817 $add_image_markup = '';
818
819 if ( isset( $header_logo_image ) && ! empty( $header_logo_image ) ) {
820 $add_image_markup = '<div class="wcf-checkout-header-image">';
821 $add_image_markup .= '<img src="' . $header_logo_image . '" />';
822 $add_image_markup .= '</div>';
823 }
824
825 echo $add_image_markup;
826 }
827
828 /**
829 * Add text to the bootom of the checkout page.
830 *
831 * @return void
832 */
833 function show_cartflows_copyright_message() {
834 $output_string = '';
835
836 $output_string .= '<div class="wcf-footer-primary">';
837 $output_string .= '<div class="wcf-footer-content">';
838 $output_string .= '<p class="wcf-footer-message">';
839 $output_string .= 'Checkout powered by CartFlows';
840 $output_string .= '</p>';
841 $output_string .= '</div>';
842 $output_string .= '</div>';
843
844 echo $output_string;
845 }
846
847 /**
848 * Redirect users to our checkout if hidden param
849 *
850 * @param string $redirect redirect url.
851 * @param object $user user.
852 * @return string
853 */
854 function after_login_redirect( $redirect, $user ) {
855
856 if ( isset( $_POST['_wcf_checkout_id'] ) ) {
857
858 $checkout_id = intval( $_POST['_wcf_checkout_id'] );
859
860 $redirect = get_permalink( $checkout_id );
861 }
862
863 return $redirect;
864 }
865
866 /**
867 * Display coupon code field after review order fields.
868 */
869 function display_custom_coupon_field() {
870
871 $coupon_enabled = apply_filters( 'woocommerce_coupons_enabled', true );
872
873 if ( ! $coupon_enabled ) {
874 return;
875 }
876
877 ob_start();
878
879 ?>
880 <div class="wcf-custom-coupon-field">
881 <div class="wcf-coupon-col-1">
882 <span>
883 <input type="text" name="coupon_code" class="input-text cf-coupon-code-input" placeholder="<?php _e( 'Coupon Code', 'cartflows' ); ?>" id="coupon_code" value="">
884 </span>
885 </div>
886 <div class="wcf-coupon-col-2">
887 <span>
888 <button type="button" class="button cf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply"><?php _e( 'Apply', 'cartflows' ); ?></button>
889 </span>
890 </div>
891 </div>
892
893 <?php
894
895 echo ob_get_clean();
896 }
897
898 /**
899 * Apply coupon on submit of custom coupon form.
900 */
901 function apply_coupon() {
902
903 check_ajax_referer( 'cf-apply-coupon', 'security' );
904
905 $result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) );
906
907 echo json_encode( $result );
908 die();
909 }
910
911 /**
912 * Added ajax nonce to localize variable.
913 *
914 * @param array $vars localize variables.
915 */
916 function add_localize_vars( $vars ) {
917
918 $vars['cf_validate_coupon_nonce'] = wp_create_nonce( 'cf-apply-coupon' );
919
920 return $vars;
921 }
922
923 /**
924 * Add custom class to the fields to change the UI to three column.
925 *
926 * @param array $fields fields.
927 */
928 function add_three_column_layout_fields( $fields ) {
929
930 if ( empty( $fields['billing']['billing_address_2'] ) ) {
931
932 if ( isset( $fields['billing']['billing_address_1'] ) && is_array( $fields['billing']['billing_address_1'] ) ) {
933 $fields['billing']['billing_address_1']['class'][] = 'form-row-full';
934 }
935 }
936
937 if ( empty( $fields['shipping']['shipping_address_2'] ) ) {
938
939 if ( isset( $fields['shipping']['shipping_address_1'] ) && is_array( $fields['shipping']['shipping_address_1'] ) ) {
940 $fields['shipping']['shipping_address_1']['class'][] = 'form-row-full';
941 }
942 }
943
944 if ( isset( $fields['billing']['billing_city'] ) &&
945 isset( $fields['billing']['billing_state'] ) && isset( $fields['billing']['billing_postcode'] ) ) {
946
947 $fields['billing']['billing_city']['class'] = array( 'wcf-form-col-3' );
948 $fields['billing']['billing_state']['class'] = array( 'wcf-form-col-3' );
949 $fields['billing']['billing_postcode']['class'] = array( 'wcf-form-col-3' );
950 }
951
952 if ( isset( $fields['shipping']['shipping_city'] ) &&
953 isset( $fields['shipping']['shipping_state'] ) && isset( $fields['shipping']['shipping_postcode'] ) ) {
954
955 $fields['shipping']['shipping_city']['class'] = array( 'wcf-form-col-3' );
956 $fields['shipping']['shipping_state']['class'] = array( 'wcf-form-col-3' );
957 $fields['shipping']['shipping_postcode']['class'] = array( 'wcf-form-col-3' );
958 }
959
960 return $fields;
961 }
962
963 /**
964 * Add opening dev
965 *
966 * @since 1.0.0
967 */
968 function order_wrap_div_start() {
969
970 echo "<div class='wcf-order-wrap'> ";
971 }
972
973 /**
974 * Add closing dev
975 *
976 * @since 1.0.0
977 */
978 function order_wrap_div_end() {
979
980 echo '</div> ';
981 }
982 }
983
984 /**
985 * Kicking this off by calling 'get_instance()' method
986 */
987 Cartflows_Checkout_Markup::get_instance();
988