'
);
// Append our div, do our calculation and then remove it
$( 'body' ).append( div );
const w1 = $( 'div', div ).innerWidth();
div.css( 'overflow-y', 'scroll' );
const w2 = $( 'div', div ).innerWidth();
$( div ).remove();
return w1 - w2;
};
wcf_qv_close_modal();
//wcf_update_summary_height();
window.addEventListener( 'resize', function () {
wcf_update_summary_height();
} );
/* Add to cart ajax */
/**
* wcf_add_to_cart_ajax class.
*/
const wcf_add_to_cart_ajax = function () {
modal_wrap
.off(
'click',
'#wcf-quick-view-content .single_add_to_cart_button'
)
.off( 'wcf_added_to_cart' )
.on(
'click',
'#wcf-quick-view-content .single_add_to_cart_button',
this.onAddToCart
)
.on( 'wcf_added_to_cart', this.updateButton );
};
/**
* Handle the add to cart event.
*
* @param {Object} e event data.
*/
wcf_add_to_cart_ajax.prototype.onAddToCart = function ( e ) {
e.preventDefault();
const $form = $( this ).closest( 'form' );
// If the form inputs are invalid
if ( ! $form[ 0 ].checkValidity() ) {
$form[ 0 ].reportValidity();
return false;
}
const $thisbutton = $( this ),
product_id =
$form.find( 'input[name="product_id"]' ).val() || '',
variation_id =
$form.find( 'input[name="variation_id"]' ).val() || '',
choose_var = $( '.wcf-variation-popup-open' ),
qty_wrap = choose_var.closest( '.wcf-qty-row' ),
qty_selection = qty_wrap.find( '.wcf-qty-selection' ),
input_quantity = qty_selection.val() || 1,
qty_options = qty_wrap.data( 'options' ),
checkout_id = $( '._wcf_checkout_id' ).val(),
item_wrap = qty_wrap.find( '.wcf-item-wrap' );
qty_options.input_quantity = input_quantity;
qty_options.checkout_id = checkout_id;
if ( $thisbutton.is( '.single_add_to_cart_button' ) ) {
$thisbutton.removeClass( 'added' );
$thisbutton.addClass( 'loading' );
// Ajax action.
if ( variation_id !== '' ) {
jQuery.ajax( {
url: cartflows.ajax_url,
type: 'POST',
data: {
action: 'wcf_add_cart_single_product',
form_data: $form.serialize(),
product_id,
variation_id,
quantity: input_quantity,
option: qty_options,
security: cartflows.wcf_quick_view_add_cart_nonce,
},
dataType: 'json',
success( response ) {
if (
response.hasOwnProperty( 'cartflows_data' ) &&
'yes' === response.cartflows_data.added_to_cart
) {
const result = response.cartflows_data;
/* Update Attributes to Name in summary */
choose_var
.closest( '.wcf-item' )
.find( '.wcf-display-attributes' )
.html( result.display_attr );
choose_var
.closest( '.wcf-item' )
.find( '.wcf-item-image' )
.html( result.variation_image );
/* Update Variaiton id in attributes */
choose_var.attr(
'data-variation',
result.variation_id
);
qty_options.variation_id = result.variation_id;
qty_options.original_price =
result.original_price;
qty_options.discounted_price =
result.discounted_price;
qty_options.subscription_price =
result.subscription_price;
qty_options.sign_up_fee = result.signup_fee;
qty_wrap.attr(
'data-options',
JSON.stringify( qty_options )
);
/* Item selector */
const var_selection = qty_wrap.find(
'.wcf-item-selector'
);
if ( var_selection.length > 0 ) {
const var_options = qty_wrap.data(
'options'
);
var_options.variation_id =
result.variation_id;
qty_wrap.attr(
'data-options',
JSON.stringify( var_options )
);
}
/* Set display data */
qty_wrap
.find( '.wcf-display-quantity' )
.html( result.display_quantity );
qty_wrap
.find( '.wcf-display-price' )
.html( result.display_price );
qty_wrap
.find( '.wcf-display-discount-value' )
.html( result.display_discount_value );
qty_wrap
.find( '.wcf-display-discount-percent' )
.html( result.display_discount_percent );
item_wrap
.find( '.wcf_subscription_price' )
.html( result.display_subscription_price );
item_wrap
.find( '.wcf_subscription_period' )
.html(
result.display_subscription_details
);
item_wrap
.find( '.wcf_subscription_fee' )
.html( result.display_signup_fee );
item_wrap
.find( '.wcf_subscription_free_trial' )
.html( result.trial_period_string );
}
// Trigger event so themes can refresh other areas.
$( document.body ).trigger( 'wc_fragment_refresh' );
modal_wrap.trigger( 'wcf_added_to_cart', [
$thisbutton,
] );
},
} );
} /*else {
jQuery.ajax ({
url: cartflows.ajax_url,
type:'POST',
data:'action=wcf_add_cart_single_product&product_id=' + product_id + '&quantity=' + quantity,
success:function(results) {
// Trigger event so themes can refresh other areas.
$( document.body ).trigger( 'wc_fragment_refresh' );
//modal_wrap.trigger( 'wcf_added_to_cart', [ $thisbutton ] );
$( "body" ).trigger( "update_checkout" );
wcf_qv_close_btn.trigger( 'click' );
}
});
}*/
}
};
/**
* Update cart page elements after add to cart events.
*
*/
wcf_add_to_cart_ajax.prototype.updateButton = function () {
$( 'body' ).trigger( 'update_checkout' );
wcf_qv_close_btn.trigger( 'click' );
};
/**
* Init wcf_add_to_cart_ajax.
*/
new wcf_add_to_cart_ajax();
};
const wcf_two_step_validations = function () {
const $billing_inputs = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-billing-fields, .wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-account-fields'
).find(
'input[type="text"], input[type="tel"], input[type="email"], input[type="password"]'
);
const $billing_chekboxes = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-billing-fields, .wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-account-fields'
).find( 'input[type="checkbox"]' );
const $billing_select = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-billing-fields'
).find( '.select2' );
const $shipping_inputs = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-shipping-fields'
).find(
'input[type="text"], input[type="tel"], input[type="email"], input[type="password"]'
);
const $shipping_chekboxes = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-shipping-fields .woocommerce-shipping-fields__field-wrapper'
).find( 'input[type="checkbox"]' );
const $shipping_select = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout .woocommerce-shipping-fields'
).find( '.select2' );
const is_ship_to_diff = $(
'.wcf-embed-checkout-form-two-step form.woocommerce-checkout'
)
.find(
'h3#ship-to-different-address input[type="checkbox"]:checked'
)
.val();
//Add focus class on clicked on input types
let access = true,
field_focus = '';
Array.from( $billing_inputs ).forEach( function ( $this ) {
const type = $this.type,
name = $this.name,
field_row = $this.closest( '.form-row' ),
field_value = $.trim( $this.value );
let has_class = field_row.classList.contains( 'validate-required' );
// whiteSpace = /\s/g.test(field_value);
if ( name === 'account_password' || name === 'account_username' ) {
const create_acc_checkbox = document.getElementById(
'createaccount'
);
if ( create_acc_checkbox ) {
if ( $( create_acc_checkbox ).is( ':checked' ) ) {
has_class = true;
} else {
has_class = false;
}
} else {
has_class = true;
}
}
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
if (
'email' === type &&
false ===
/^([a-zA-Z0-9_\+\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,14})$/.test(
field_value
)
) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
}
$this.classList.remove( 'field-required' );
}
} );
Array.from( $billing_chekboxes ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains( 'validate-required' );
let field_value = false;
if ( $( $this ).is( ':checked' ) ) {
field_value = true;
}
if ( has_class && false === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
Array.from( $billing_select ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains( 'validate-required' ),
field_value = $.trim(
field_row.querySelector(
'.select2-selection__rendered[title]'
)
);
//Need to update naming convention.
name = field_row.querySelector( 'select' ).name; //eslint-disable-line
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
if ( '1' === is_ship_to_diff ) {
Array.from( $shipping_inputs ).forEach( function ( $this ) {
const type = $this.type,
field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
),
field_value = $.trim( $this.value );
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
if (
'email' === type &&
false ===
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(
field_value
)
) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
}
$this.classList.remove( 'field-required' );
}
} );
Array.from( $shipping_select ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
),
field_value = $.trim(
field_row.querySelector(
'.select2-selection__rendered[title]'
)
);
//Need to update naming convention.
name = field_row.querySelector( 'select' ).name; //eslint-disable-line
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
Array.from( $shipping_chekboxes ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
);
let field_value = false;
if ( $( $this ).is( ':checked' ) ) {
field_value = true;
}
if ( has_class && false === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
}
// Focus the errored field
if ( '' !== field_focus ) {
field_focus.focus();
}
return access;
};
/*$(".wcf-qty [type='number']").on('keyup mouseup', function (event) {
var input = jQuery(this).val();
var input2 = input+jQuery(this).text();
var step = jQuery(this).attr("step");
var min = jQuery(this).attr("min");
if(!Number.isNaN(input2)){
if(parseInt(input2) > min){
var remainder = input2%step;
if(remainder !== 0){
var new_value = parseInt(input2) - remainder;
jQuery(this).val(new_value);
}
}
}
}).trigger('mouseup');
jQuery(".wcf-qty [type='number']").on('focusout',function (evt) {
// var input = String.fromCharCode(evt.which);
var input = jQuery(this).val();
// var input_text = jQuery(this).text();
// if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) {
var min = jQuery(this).attr("min");
if(!Number.isNaN(input)){
if(parseInt(input) < min){
jQuery(this).val(min);
}
}
});*/
const wcf_order_bump_buttons = function () {
$( document ).on( 'click', '.wcf-bump-order-cb-button', function () {
const $this = $( this ),
parent_class = $this.closest( '.wcf-bump-order-action' ),
input = parent_class.find( 'input[type="checkbox"]' );
if ( $this.hasClass( 'wcf-bump-add-to-cart' ) ) {
input.attr( 'checked', true );
$this.text( $this.data( 'adding' ) );
} else {
input.attr( 'checked', false );
$this.text( $this.data( 'removing' ) );
}
parent_class.find( '.wcf-bump-order-cb' ).trigger( 'change' );
} );
};
const quantity_changer = function () {
$( '.wcf-qty-selection-btn' ).click( function ( e ) {
e.preventDefault();
const quantity_input = $( this )
.parents( '.wcf-qty' )
.find( '.wcf-qty-selection' ),
is_sold_individually = Boolean(
quantity_input.data( 'sale-limit' )
);
// Return if the product is set to sold 1 per order.
if ( is_sold_individually ) {
return false;
}
const val = parseInt( quantity_input.val(), 10 ),
min_value = parseInt( quantity_input.attr( 'min' ) ),
max_value = parseInt( quantity_input.attr( 'max' ) );
if ( $( e.target ).hasClass( 'wcf-qty-increment' ) ) {
quantity_input.val( val + 1 );
// Disable the quantity selector if the max quantity is reached.
if ( max_value && quantity_input.val() >= max_value ) {
$( e.target ).addClass( 'max-quantity-reached' );
} else {
$( e.target ).removeClass( 'max-quantity-reached' );
}
} else {
$( '.wcf-qty-increment' ).removeClass( 'max-quantity-reached' );
quantity_input.val( val <= min_value ? min_value : val - 1 );
}
$( '.wcf-qty-selection' ).trigger( 'change' );
} );
};
const ob_quantity_changer = function () {
let wcf_order_bump_qty_update = false;
$( document ).on( 'click', '.wcf-ob-qty-selection-btn', function ( e ) {
e.preventDefault();
if ( true === wcf_order_bump_qty_update ) {
return false;
}
wcf_order_bump_qty_update = true;
const $this = $( this ),
quantity_input = $this
.parents( '.wcf-ob-qty-selection-wrap' )
.find( '.wcf-order-bump-quantity-updater' ),
min_value = quantity_input.attr( 'min' );
let updated_qty = '';
const val = parseInt( quantity_input.val(), 10 );
if ( $( e.target ).hasClass( 'wcf-ob-qty-increment' ) ) {
updated_qty = val + 1;
quantity_input.val( updated_qty );
} else {
updated_qty = val <= min_value ? min_value : val - 1;
quantity_input.val( updated_qty );
}
// Make a ajax call to update the quantity in the cart.
update_ob_quantity( $this, updated_qty );
wcf_order_bump_qty_update = false;
$( '.wcf-order-bump-quantity-updater' ).trigger( 'change' );
} );
};
const update_ob_quantity = function ( $this, updated_qty ) {
const bump_offer_wrap = $this.closest( '.wcf-bump-order-wrap' ),
checkbox_field = bump_offer_wrap.find( '#wcf-bump-order-cb' ),
bump_offer_data = checkbox_field.attr( 'data-ob_data' ),
ob_data = checkbox_field.data( 'ob_data' ),
product_id = ob_data.product_id;
const data = {
_wcf_product_id: product_id,
_bump_offer_data: bump_offer_data ? bump_offer_data : '',
_bump_offer_qty: updated_qty > 0 ? updated_qty : '',
security: cartflows.wcf_update_order_bump_qty_nonce,
action: 'wcf_update_order_bump_qty',
};
if ( false === checkbox_field.is( ':checked' ) ) {
return;
}
data._wcf_bump_product_action = 'add_bump_product';
// Display spinner for specific order bump.
bump_offer_wrap.block( {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6,
},
} );
wcf_display_spinner();
$.ajax( {
url: cartflows.ajax_url,
data,
dataType: 'json',
type: 'POST',
success( response ) {
// Re-calculate the cart total
wcf_re_calculate_totals();
wcf_remove_spinner( response );
},
error() {
$( '.woocommerce-checkout-review-order-table' ).unblock();
},
} );
return false;
};
const multistep_checkout_buttons_navigation = function () {
let previous_step = 'billing',
current_step = 'billing';
// Next button.
$( document ).on(
'click',
'.wcf-multistep-nav-next-btn',
function wcf_show_next_step( e ) {
e.preventDefault();
const next_step_element = $( '.wcf-multistep-nav-next-btn' ),
next_step_element_target = next_step_element.attr(
'data-target'
);
if ( current_step !== next_step_element_target ) {
if ( wcf_multistep_field_validations() ) {
remove_current_step_class();
previous_step = current_step;
current_step = next_step_element_target;
if ( 'shipping' === next_step_element_target ) {
show_shipping_step();
} else if ( 'payment' === next_step_element_target ) {
show_payment_step();
}
scrollToTop();
}
}
}
);
// Back button.
$( document ).on(
'click',
'.wcf-multistep-nav-back-btn',
function wcf_show_previous_step( e ) {
e.preventDefault();
const previous_step_element = $(
'.wcf-multistep-nav-back-btn'
);
previous_step_element_target = previous_step_element.attr(
'data-target'
);
if ( current_step !== previous_step_element_target ) {
if ( wcf_multistep_field_validations() ) {
remove_current_step_class();
previous_step = current_step;
current_step = previous_step_element_target;
if ( '' === previous_step_element_target ) {
previous_step_element.css( 'visibility', 'hidden' );
} else if (
'shipping' === previous_step_element_target
) {
show_shipping_step();
} else if (
'billing' === previous_step_element_target
) {
show_billing_step();
}
scrollToTop();
}
}
}
);
// Breadcrumbs.
$( document ).on(
'click',
'.wcf-checkout-breadcrumb a',
function wcf_show_previous_step( e ) {
e.preventDefault();
const breadcrum_tab = $( e.target ).attr( 'data-tab' );
if ( current_step !== breadcrum_tab ) {
if ( wcf_multistep_field_validations() ) {
previous_step = current_step;
current_step = breadcrum_tab;
remove_current_step_class();
if ( 'billing' === breadcrum_tab ) {
show_billing_step();
} else if ( 'shipping' === breadcrum_tab ) {
show_shipping_step();
} else if ( 'payment' === breadcrum_tab ) {
show_payment_step();
}
scrollToTop();
}
}
}
);
// Custom sections.
$( document ).on(
'click',
'.wcf-step-link',
function wcf_show_previous_step( e ) {
e.preventDefault();
const tab_target = $( e.target ).attr( 'data-target' );
if ( current_step !== tab_target ) {
if ( wcf_multistep_field_validations() ) {
previous_step = current_step;
current_step = tab_target;
remove_current_step_class();
if ( 'billing' === tab_target ) {
show_billing_step();
} else if ( 'shipping' === tab_target ) {
show_shipping_step();
}
}
}
}
);
function show_billing_step() {
const next_step_element = $( '.wcf-multistep-nav-next-btn' ),
previous_step_element = $( '.wcf-multistep-nav-back-btn' );
if ( 'shipping' === previous_step ) {
$( '.wcf-embed-checkout-form' ).removeClass( 'wcf-shipping' );
}
if ( 'payment' === previous_step ) {
$( '.wcf-embed-checkout-form' ).removeClass( 'wcf-payment' );
}
$( '.wcf-embed-checkout-form' ).addClass( 'wcf-billing' );
if ( cartflows.is_hide_shipping_tab ) {
next_step_element.attr( 'data-target', 'payment' );
} else {
next_step_element.attr( 'data-target', 'shipping' );
}
previous_step_element.attr( 'data-target', '' );
$( '.wcf-checkout-breadcrumb.information-step a' ).addClass(
'wcf-current-step'
);
next_step_element.text(
cartflows.multistep_buttons_strings.billing
);
}
function show_shipping_step() {
const next_step_element = $( '.wcf-multistep-nav-next-btn' ),
previous_step_element = $( '.wcf-multistep-nav-back-btn' );
if ( 'billing' === previous_step ) {
$( '.wcf-embed-checkout-form' ).removeClass( 'wcf-billing' );
}
if ( 'payment' === previous_step ) {
$( '.wcf-embed-checkout-form' ).removeClass( 'wcf-payment' );
}
$( '.wcf-embed-checkout-form' ).addClass( 'wcf-shipping' );
next_step_element.attr( 'data-target', 'payment' );
previous_step_element.attr( 'data-target', 'billing' );
$( '.wcf-checkout-breadcrumb.shipping-step a' ).addClass(
'wcf-current-step'
);
updateEmailValue();
next_step_element.text(
cartflows.multistep_buttons_strings.shipping
);
}
function show_payment_step() {
const previous_step_element = $( '.wcf-multistep-nav-back-btn' );
if ( 'shipping' === previous_step ) {
$( '.wcf-embed-checkout-form' ).removeClass( 'wcf-shipping' );
}
if ( 'billing' === previous_step ) {
$( '.wcf-embed-checkout-form' ).removeClass( 'wcf-billing' );
}
if ( cartflows.is_hide_shipping_tab ) {
previous_step_element.attr( 'data-target', 'billing' );
} else {
previous_step_element.attr( 'data-target', 'shipping' );
}
$( '.wcf-embed-checkout-form' ).addClass( 'wcf-payment' );
$( '.wcf-checkout-breadcrumb.payment-step a' ).addClass(
'wcf-current-step'
);
updateEmailValue();
}
function updateEmailValue() {
// Update email if it is changed.
$( '.wcf-review-detail-content.contact-details' ).text(
$( '.wcf-embed-checkout-form form.woocommerce-checkout' )
.find( 'input[type="email"]' )
.val()
);
}
function scrollToTop(
scroll_to = 'wcf-embed-checkout-form',
delay = 1000
) {
$( 'html, body' ).animate(
{
scrollTop: $( '#' + scroll_to ).offset().top,
},
delay
);
}
function remove_current_step_class() {
if ( $( '.wcf-current-step' ).length ) {
$( '.wcf-current-step' ).removeClass( 'wcf-current-step' );
}
}
const wcf_multistep_field_validations = function () {
//Add focus class on clicked on input types
let access = true,
field_focus = '';
if ( 'billing' === current_step ) {
const $billing_inputs = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-billing-fields-custom, .wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-billing-fields, .wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-account-fields'
).find(
'input[type="text"], input[type="tel"], input[type="email"], input[type="password"]'
);
const $billing_chekboxes = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-billing-fields, .wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-account-fields'
).find( 'input[type="checkbox"]' );
const $billing_select = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-billing-fields'
).find( '.select2' );
Array.from( $billing_inputs ).forEach( function ( $this ) {
const type = $this.type,
name = $this.name,
field_row = $this.closest( '.form-row' ),
field_value = $.trim( $this.value );
let has_class = field_row.classList.contains(
'validate-required'
);
// whiteSpace = /\s/g.test(field_value);
if ( name === 'billing_password' ) {
if (
$( '.wcf-email-validation-block' ).hasClass(
'success'
) &&
! cartflows?.multistep_buttons_strings
?.is_guest_checkout
) {
has_class = true;
} else {
has_class = false;
}
}
if (
name === 'account_password' ||
name === 'account_username'
) {
const create_acc_checkbox = document.getElementById(
'createaccount'
);
if ( create_acc_checkbox ) {
if ( $( create_acc_checkbox ).is( ':checked' ) ) {
has_class = true;
} else {
has_class = false;
}
} else {
has_class = true;
}
}
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
if (
'email' === type &&
false ===
/^([a-zA-Z0-9_\+\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,14})$/.test(
field_value
)
) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
}
$this.classList.remove( 'field-required' );
}
} );
Array.from( $billing_chekboxes ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
);
let field_value = false;
if ( $( $this ).is( ':checked' ) ) {
field_value = true;
}
if ( has_class && false === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
Array.from( $billing_select ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
),
field_value = $.trim(
field_row.querySelector(
'.select2-selection__rendered[title]'
)
);
//Need to update naming convention.
name = field_row.querySelector( 'select' ).name; //eslint-disable-line
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
}
if ( 'shipping' === current_step ) {
const $shipping_inputs = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-shipping-fields'
).find(
'input[type="text"], input[type="tel"], input[type="email"], input[type="password"]'
);
const $shipping_chekboxes = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-shipping-fields .woocommerce-shipping-fields__field-wrapper'
).find( 'input[type="checkbox"]' );
const $shipping_select = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout .woocommerce-shipping-fields'
).find( '.select2' );
const is_ship_to_diff = $(
'.wcf-embed-checkout-form-modern-checkout.wcf-modern-skin-multistep form.woocommerce-checkout'
)
.find(
'h3#ship-to-different-address input[type="checkbox"]:checked'
)
.val();
if ( '1' === is_ship_to_diff ) {
Array.from( $shipping_inputs ).forEach( function ( $this ) {
const type = $this.type,
field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
),
field_value = $.trim( $this.value );
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
if (
'email' === type &&
false ===
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(
field_value
)
) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
}
$this.classList.remove( 'field-required' );
}
} );
Array.from( $shipping_select ).forEach( function ( $this ) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
),
field_value = $.trim(
field_row.querySelector(
'.select2-selection__rendered[title]'
)
);
//Need to update naming convention.
name = field_row.querySelector( 'select' ).name; //eslint-disable-line
if ( has_class && '' === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
Array.from( $shipping_chekboxes ).forEach( function (
$this
) {
const field_row = $this.closest( '.form-row' ),
has_class = field_row.classList.contains(
'validate-required'
);
let field_value = false;
if ( $( $this ).is( ':checked' ) ) {
field_value = true;
}
if ( has_class && false === field_value ) {
$this.classList.add( 'field-required' );
access = false;
if ( '' === field_focus ) {
field_focus = $this;
}
} else {
$this.classList.remove( 'field-required' );
}
} );
}
}
// Focus the errored field
if ( '' !== field_focus ) {
field_focus.focus();
}
return access;
};
};
$( function () {
wcf_remove_product();
wcf_animate_browser_tab();
if ( 'yes' === cartflows.allow_autocomplete_zipcode ) {
wcf_autocomplete_zip_data();
}
wcf_product_quantity_var_options();
wcf_do_not_remove_single_product();
wcf_order_bump_ajax();
wcf_order_bump_buttons();
if ( $( '.wcf-embed-checkout-form-two-step' ).length > 0 ) {
wcf_nav_tab_hide_show_events();
}
//In multi checkout case we need to update the cart item key of the data-option for the product options.
wcf_update_product_options_cart_item_key();
quantity_changer();
ob_quantity_changer();
multistep_checkout_buttons_navigation();
} );
} )( jQuery );