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