jQuery(function(i){"use strict";try{var n=Stripe(wc_stripe_params.key,{locale:wc_stripe_params.stripe_locale||"auto"})}catch(e){return void console.log(e)}var t,o,s,e=Object.keys(wc_stripe_params.elements_options).length?wc_stripe_params.elements_options:{},r=Object.keys(wc_stripe_params.sepa_elements_options).length?wc_stripe_params.sepa_elements_options:{},a=n.elements(e),c=a.create("iban",r),m={getAjaxURL:function(e){return wc_stripe_params.ajaxurl.toString().replace("%%endpoint%%","wc_stripe_"+e)},unmountElements:function(){"yes"===wc_stripe_params.inline_cc_form?t.unmount("#stripe-card-element"):(t.unmount("#stripe-card-element"),o.unmount("#stripe-exp-element"),s.unmount("#stripe-cvc-element"))},mountElements:function(){i("#stripe-card-element").length&&("yes"!==wc_stripe_params.inline_cc_form?(t.mount("#stripe-card-element"),o.mount("#stripe-exp-element"),s.mount("#stripe-cvc-element")):t.mount("#stripe-card-element"))},createElements:function(){var e={base:{iconColor:"#666EE8",color:"#31325F",fontSize:"15px","::placeholder":{color:"#CFD7E0"}}},r={focus:"focused",empty:"empty",invalid:"invalid"},e=wc_stripe_params.elements_styling||e,r=wc_stripe_params.elements_classes||r;"yes"===wc_stripe_params.inline_cc_form?(t=a.create("card",{style:e,hidePostalCode:!0,hideIcon:!0})).addEventListener("change",function(e){m.onCCFormChange(),e.error&&i(document.body).trigger("stripeError",e)}):(t=a.create("cardNumber",{style:e,classes:r,showIcon:!1}),o=a.create("cardExpiry",{style:e,classes:r}),s=a.create("cardCvc",{style:e,classes:r}),t.addEventListener("change",function(e){m.onCCFormChange(),m.updateCardBrand(e.brand),e.error&&i(document.body).trigger("stripeError",e)}),o.addEventListener("change",function(e){m.onCCFormChange(),e.error&&i(document.body).trigger("stripeError",e)}),s.addEventListener("change",function(e){m.onCCFormChange(),e.error&&i(document.body).trigger("stripeError",e)})),"yes"===wc_stripe_params.is_checkout?i(document.body).on("updated_checkout",function(){i("#stripe-card-element").children().length||(t&&m.unmountElements(),m.mountElements(),i("#stripe-iban-element").length&&c.mount("#stripe-iban-element"))}):(i("form#add_payment_method").length||i("form#order_review").length)&&(m.mountElements(),i("#stripe-iban-element").length&&c.mount("#stripe-iban-element"))},updateCardBrand:function(e){var r={visa:"stripe-visa-brand",mastercard:"stripe-mastercard-brand",amex:"stripe-amex-brand",discover:"stripe-discover-brand",diners:"stripe-diners-brand",jcb:"stripe-jcb-brand",unknown:"stripe-credit-card-brand"},t=i(".stripe-card-brand"),e=e in r?r[e]:"stripe-credit-card-brand";i.each(r,function(e,r){t.removeClass(r)}),t.addClass(e)},init:function(){"yes"!==wc_stripe_params.is_change_payment_page&&"yes"!==wc_stripe_params.is_pay_for_order_page||i(document.body).trigger("wc-credit-card-form-init"),i("form.woocommerce-checkout").length&&(this.form=i("form.woocommerce-checkout")),i("form.woocommerce-checkout").on("checkout_place_order_stripe checkout_place_order_stripe_bancontact checkout_place_order_stripe_sofort checkout_place_order_stripe_giropay checkout_place_order_stripe_ideal checkout_place_order_stripe_alipay checkout_place_order_stripe_sepa checkout_place_order_stripe_boleto checkout_place_order_stripe_oxxo",this.onSubmit),i("form#order_review").length&&(this.form=i("form#order_review")),i("form#order_review, form#add_payment_method").on("submit",this.onSubmit),i("form#add_payment_method").length&&(this.form=i("form#add_payment_method")),i("form.woocommerce-checkout").on("change",this.reset),i(document).on("stripeError",this.onError).on("checkout_error",this.reset),c.on("change",this.onSepaError),(i("#early_renewal_modal_submit[data-payment-method]").length?i("#early_renewal_modal_submit[data-payment-method=stripe]"):i("#early_renewal_modal_submit")).on("click",this.onEarlyRenewalSubmit),m.createElements(),window.addEventListener("hashchange",m.onHashChange),m.maybeConfirmIntent(),i(document).on("change",".wc_payment_methods",function(){var n,e;i("#stripe_boleto_tax_id").length&&(n=function(e){return 12<=e.replace(/\D/g,"").length?"00.000.000/0000-00":"000.000.000-009999"},e={onKeyPress:function(e,r,t,o){t.mask(n.apply({},arguments),o)}},i("#stripe_boleto_tax_id").mask(n,e))})},isStripeChosen:function(){return i("#payment_method_stripe, #payment_method_stripe_bancontact, #payment_method_stripe_sofort, #payment_method_stripe_giropay, #payment_method_stripe_ideal, #payment_method_stripe_alipay, #payment_method_stripe_sepa, #payment_method_stripe_eps, #payment_method_stripe_multibanco, #payment_method_stripe_boleto, #payment_method_stripe_oxxo").is(":checked")||i("#payment_method_stripe").is(":checked")&&"new"===i('input[name="wc-stripe-payment-token"]:checked').val()||i("#payment_method_stripe_sepa").is(":checked")&&"new"===i('input[name="wc-stripe-payment-token"]:checked').val()},isStripeSaveCardChosen:function(){return i("#payment_method_stripe").is(":checked")&&i('input[name="wc-stripe-payment-token"]').is(":checked")&&"new"!==i('input[name="wc-stripe-payment-token"]:checked').val()||i("#payment_method_stripe_sepa").is(":checked")&&i('input[name="wc-stripe_sepa-payment-token"]').is(":checked")&&"new"!==i('input[name="wc-stripe_sepa-payment-token"]:checked').val()},isStripeCardChosen:function(){return i("#payment_method_stripe").is(":checked")},isBancontactChosen:function(){return i("#payment_method_stripe_bancontact").is(":checked")},isGiropayChosen:function(){return i("#payment_method_stripe_giropay").is(":checked")},isIdealChosen:function(){return i("#payment_method_stripe_ideal").is(":checked")},isSofortChosen:function(){return i("#payment_method_stripe_sofort").is(":checked")},isAlipayChosen:function(){return i("#payment_method_stripe_alipay").is(":checked")},isSepaChosen:function(){return i("#payment_method_stripe_sepa").is(":checked")},isP24Chosen:function(){return i("#payment_method_stripe_p24").is(":checked")},isEpsChosen:function(){return i("#payment_method_stripe_eps").is(":checked")},isMultibancoChosen:function(){return i("#payment_method_stripe_multibanco").is(":checked")},isBoletoChosen:function(){return i("#payment_method_stripe_boleto").is(":checked")},isOxxoChosen:function(){return i("#payment_method_stripe_oxxo").is(":checked")},hasSource:function(){return 0').addClass("stripe-source").attr("name","stripe_source").val(r)),i("form#add_payment_method").length||i("#wc-stripe-change-payment-method").length?m.sourceSetup(e):m.form.trigger("submit"))},sourceSetup:function(e){var r={error:{type:"api_connection_error"}},t=e.paymentMethod&&e.paymentMethod.id?e.paymentMethod.id:e.source&&e.source.id?e.source.id:void 0;i.post({url:m.getAjaxURL("create_setup_intent"),dataType:"json",data:{stripe_source_id:t,nonce:wc_stripe_params.add_card_nonce},error:function(){i(document.body).trigger("stripeError",r)}}).done(function(e){return"success"===e.status?(i("form#add_payment_method").length&&i(m.form).off("submit",m.form.onSubmit),void m.form.trigger("submit")):void("requires_action"===e.status?n.confirmCardSetup(e.client_secret,{payment_method:t}).then(function(e){e.error?i(document.body).trigger("stripeError",e):(i("form#add_payment_method").length&&i(m.form).off("submit",m.form.onSubmit),m.form.trigger("submit"))}).catch(function(e){console.log(e),i(document.body).trigger("stripeError",{error:e})}):i(document.body).trigger("stripeError",e))})},onSubmit:function(){if(!m.isStripeChosen())return!0;if(m.isStripeSaveCardChosen()||m.hasSource())return!0;if(m.isBancontactChosen()||m.isGiropayChosen()||m.isIdealChosen()||m.isAlipayChosen()||m.isSofortChosen()||m.isP24Chosen()||m.isEpsChosen()||m.isMultibancoChosen())return!0;if(m.block(),m.isBoletoChosen()){if(!i("#stripe_boleto_tax_id").val())return m.submitError(wc_stripe_params.cpf_cnpj_required_msg),m.unblock(),!1;m.handleBoleto()}else m.isOxxoChosen()?m.handleOxxo():m.createSource();return!1},handleBoleto:function(){m.executeCheckout("boleto",function(r){n.confirmBoletoPayment(r.client_secret,r.confirm_payment_data).then(function(e){m.handleConfirmResponse(r,e)})})},executeCheckout:function(e,r){const t=m.form.serializeArray().reduce((e,r)=>(e[r.name]=r.value,e),{});"order_review"===m.form.attr("id")?(t._ajax_nonce=wc_stripe_params.updatePaymentIntentNonce,t.order_id=wc_stripe_params.orderId,t.stripe_order_key=wc_stripe_params.stripe_order_key,i.ajax({url:m.getAjaxURL(e+"_update_payment_intent"),type:"POST",data:t,success:function(e){if("success"!==e.result)return m.submitError(e.messages),void m.unblock();r(e)}})):i.ajax({url:wc_stripe_params.checkout_url,type:"POST",data:t,success:function(e){if("success"!==e.result)return m.submitError(e.messages,!0),void m.unblock();r(e)}})},handleConfirmResponse:function(e,r){r.error?i(document.body).trigger("stripeError",r):-1===e.redirect.indexOf("https://")||-1===e.redirect.indexOf("http://")?window.location=e.redirect:window.location=decodeURI(e.redirect)},handleOxxo:function(){m.executeCheckout("oxxo",function(r){n.confirmOxxoPayment(r.client_secret,r.confirm_payment_data).then(function(e){m.handleConfirmResponse(r,e)})})},onCCFormChange:function(){m.reset()},reset:function(){i(".wc-stripe-error, .stripe-source").remove()},onSepaError:function(e){var r=m.getSelectedPaymentElement().parents("li").eq(0).find(".stripe-source-errors");e.error?(console.log(e.error.message),i(r).html('
'),i(r).find("li").text(e.error.message)):i(r).html("")},onError:function(e,r){var t=r.error.message,o=m.getSelectedPaymentElement().closest(".wc_payment_method"),n=o.find(".woocommerce-SavedPaymentMethods-tokenInput");o=i("body").hasClass("woocommerce-stripe-prb-clicked")?(i("body").removeClass("woocommerce-stripe-prb-clicked"),i("div.woocommerce-notices-wrapper").first()):n.length?(n=n.filter(":checked")).closest(".woocommerce-SavedPaymentMethods-new").length?i("#wc-stripe-cc-form .stripe-source-errors"):n.closest("li").find(".stripe-source-errors"):o.find(".stripe-source-errors"),m.isSepaChosen()&&"invalid_owner_name"===r.error.code&&wc_stripe_params.hasOwnProperty(r.error.code)?m.submitError(wc_stripe_params[r.error.code]):("email_invalid"===r.error.code?t=wc_stripe_params.email_invalid:"invalid_request_error"!==r.error.type&&"api_connection_error"!==r.error.type&&"api_error"!==r.error.type&&"authentication_error"!==r.error.type&&"rate_limit_error"!==r.error.type||(t=wc_stripe_params.invalid_request_error),wc_stripe_params.hasOwnProperty(r.error.code)&&(t=wc_stripe_params[r.error.code]),"card_declined"===r.error.code&&"insufficient_funds"===r.error?.decline_code&&(t=wc_stripe_params.insufficient_funds),m.reset(),i(".woocommerce-NoticeGroup-checkout").remove(),console.log(r.error.message),i(o).html(''),i(o).find("li").text(t),i(".wc-stripe-error").length&&i("html, body").animate({scrollTop:i(".wc-stripe-error").offset().top-200},200),m.unblock(),i.unblockUI())},submitError:function(e,r=!1){r||((r=i('')).find("li").text(e),e=r.html()),i(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),m.form.prepend(''+e+"
"),m.form.removeClass("processing").unblock(),m.form.find(".input-text, select, input:checkbox").trigger("blur");e="";i("#add_payment_method").length&&(e=i("#add_payment_method")),i("#order_review").length&&(e=i("#order_review")),(e=i("form.checkout").length?i("form.checkout"):e).length&&i("html, body").animate({scrollTop:e.offset().top-100},500),i(document.body).trigger("checkout_error"),m.unblock()},onHashChange:function(){var e,r,t=window.location.hash.match(/^#?confirm-(pi|si)-([^:]+):(.+)$/);!t||t.length<4||(e=t[1],r=t[2],t=decodeURIComponent(t[3]),window.location.hash="",m.openIntentModal(r,t,!1,"si"===e))},maybeConfirmIntent:function(){var e,r;i("#stripe-intent-id").length&&i("#stripe-intent-return").length&&(e=i("#stripe-intent-id").val(),r=i("#stripe-intent-return").val(),m.openIntentModal(e,r,!0,!1))},openIntentModal:function(e,r,t,o){n[o?"handleCardSetup":"handleCardPayment"](e).then(function(e){if(e.error)throw e.error;e=e[o?"setupIntent":"paymentIntent"];"requires_capture"!==e.status&&"succeeded"!==e.status||(window.location=r)}).catch(function(e){t?window.location=r:(i(document.body).trigger("stripeError",{error:e}),m.form&&m.form.removeClass("processing"),i.get(r+"&is_ajax"))})},onEarlyRenewalSubmit:function(e){return e.preventDefault(),i.ajax({url:i("#early_renewal_modal_submit").attr("href"),method:"get",success:function(e){e=JSON.parse(e);e.stripe_sca_required?m.openIntentModal(e.intent_secret,e.redirect_url,!0,!1):window.location=e.redirect_url}}),!1}};m.init()});
;
(function ($) {
'use strict';
// Update WooCommerce mini cart.
// Trigger event
$( document.body ).on( 'adding_to_cart', function() {
$('.g1-drop-toggle-badge').removeClass('g1-drop-toggle-badge-animate');
} );
$( document.body ).on( 'added_to_cart removed_from_cart', function() {
// the event is called BEFORE the cart AJAX comes back so we need a small timeout or we'll get the wrong count.
setTimeout(function() {
var $drop = $('.g1-drop-the-cart');
var count = parseInt( $drop.find( '.cart_list').data('g1-cart-count'), 10 );
if ( count > 0 ) {
$drop.find('.g1-drop-toggle-badge').removeClass('g1-drop-toggle-badge-hidden').addClass('g1-drop-toggle-badge-animate').text(count);
} else {
$drop.find('.g1-drop-toggle-badge').addClass('g1-drop-toggle-badge-hidden').text(count);
}
}, 500);
} );
// Add our custom class to the link "View Cart" after product was added to the cart.
// The "View Cart" link is located on product list, under the "Add to Cart" button.
$(document.body).on('wc_cart_button_updated', function (e, $button) {
$button.next('a.added_to_cart').addClass('g1-link g1-link-right');
});
})(jQuery);
;
( function ( $ ) {
const wcf_update_checkout_on_return = function () {
const vis = ( function () {
let stateKey, eventKey;
const keys = {
hidden: 'visibilitychange',
webkitHidden: 'webkitvisibilitychange',
mozHidden: 'mozvisibilitychange',
msHidden: 'msvisibilitychange',
};
for ( stateKey in keys ) {
if ( stateKey in document ) {
eventKey = keys[ stateKey ];
break;
}
}
return function ( c ) {
if ( c ) {
document.addEventListener( eventKey, c );
}
return ! document[ stateKey ];
};
} )();
function getCookie( name ) {
const cookieArr = document.cookie.split( ';' );
for ( let i = 0; i < cookieArr.length; i++ ) {
const cookiePair = cookieArr[ i ].split( '=' );
if ( name === cookiePair[ 0 ].trim() ) {
return decodeURIComponent( cookiePair[ 1 ] );
}
}
return null;
}
vis( function () {
const active_checkout_cookie = getCookie(
cartflows.active_checkout_cookie
);
if ( active_checkout_cookie && vis() ) {
if (
parseInt( cartflows.current_step ) !==
parseInt( active_checkout_cookie )
) {
// Add loader.
$(
'.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table'
).block( {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6,
},
} );
console.log( 'Multiple checkouts are open.' );
$( document.body ).trigger( 'update_checkout' );
$( document ).ajaxComplete( function ( event, xhr ) {
if ( ! xhr.hasOwnProperty( 'responseJSON' ) ) {
return;
}
const fragmants = xhr.responseJSON.hasOwnProperty(
'fragments'
)
? xhr.responseJSON.fragments
: null;
if (
fragmants &&
fragmants.hasOwnProperty( 'wcf_cart_data' )
) {
$( document.body ).trigger(
'wcf_cart_data_restored',
[ fragmants.wcf_cart_data ]
);
}
} );
}
}
} );
};
/**
* Checkout Custom Field Validations
* This will collect all the present fields in the woocommerce form and adds an class if the field
* is blank
*/
const wcf_custom_field_validation = function () {
/**
* Controls the display of the error message on the basis of backend setting.
*
* @param {boolean} field_required
* @param {string} field_row
* @param {string} field_wrap
*/
const add_validation_msg = function (
field_required = false,
field_row,
field_wrap
) {
field_row.find( '.wcf-field-required-error' ).remove();
if (
field_required &&
'yes' === cartflows.field_validation.is_enabled
) {
const label_text = field_row.find( 'label' ).text();
field_wrap.after(
'' +
label_text.replace( /\*/g, '' ).trim() +
' ' +
cartflows.field_validation.error_msg +
''
);
} else {
field_row.find( '.wcf-field-required-error' ).remove();
}
};
const custom_field_add_class = function (
field_value,
field_row,
field_wrap,
field_type
) {
let isError = false;
if (
field_value === '' ||
( 'select' === field_type && field_value === ' ' )
) {
if ( field_row.hasClass( 'validate-required' ) ) {
field_wrap.addClass( 'field-required' );
isError = true;
}
} else {
field_wrap.removeClass( 'field-required' );
}
add_validation_msg( isError, field_row, field_wrap );
};
const numberFieldValidation = function (
field_value,
field_row,
field_wrap,
minValue,
maxValue
) {
if (
field_value === '' ||
field_value < minValue ||
field_value > maxValue
) {
field_wrap.addClass( 'field-required' );
field_wrap.after(
'' +
cartflows.field_validation_msgs.number_field +
minValue +
' & ' +
maxValue +
''
);
} else {
field_wrap.removeClass( 'field-required' );
field_row.find( '.wcf-field-required-error' ).remove();
}
};
const fields_wrapper = $( 'form.woocommerce-checkout' ),
$all_fields = fields_wrapper.find( 'input, textarea' ),
$selects = fields_wrapper.find( 'select' );
$all_fields.on( 'blur', function () {
const $this = $( this ),
field_type = $this.attr( 'type' ),
field_row = $this.closest( 'p.form-row' ),
field_value = $this.val();
custom_field_add_class( field_value, field_row, $this, field_type );
if ( 'number' === field_type ) {
const minValue = $this.attr( 'min' );
const maxValue = $this.attr( 'max' );
numberFieldValidation(
Number( field_value ),
field_row,
$this,
Number( minValue ),
Number( maxValue )
);
}
} );
$selects.on( 'blur', function () {
const $this = $( this ),
field_row = $this.closest( 'p.form-row' ),
field_type = 'select',
field_wrap = field_row.find( '.select2-container--default' ),
field_value = field_row.find( 'select' ).val();
custom_field_add_class(
field_value,
field_row,
field_wrap,
field_type
);
} );
};
const wcf_check_is_local_storage = function () {
const test = 'test';
try {
localStorage.setItem( test, test );
localStorage.removeItem( test );
return true;
} catch ( e ) {
return false;
}
};
const wcf_persistent_data = function () {
if ( 'yes' !== cartflows.allow_persistence ) {
return;
}
if ( false === wcf_check_is_local_storage() ) {
return;
}
const checkout_cust_form =
'form.woocommerce-checkout #customer_details';
const wcf_form_data = {
set() {
const checkout_data = [];
const checkout_form = $(
'form.woocommerce-checkout #customer_details'
);
localStorage.removeItem( 'cartflows_checkout_form' );
checkout_form
.find(
'input[type=text], select, input[type=email], input[type=tel]'
)
.each( function () {
checkout_data.push( {
name: this.name,
value: this.value,
} );
} );
cartflows_checkout_form = JSON.stringify( checkout_data );
localStorage.setItem(
'cartflows_checkout_form',
cartflows_checkout_form
);
},
get() {
if (
localStorage.getItem( 'cartflows_checkout_form' ) !== null
) {
checkout_data = JSON.parse(
localStorage.getItem( 'cartflows_checkout_form' )
);
for ( let i = 0; i < checkout_data.length; i++ ) {
if (
$(
'form.woocommerce-checkout [name=' +
checkout_data[ i ].name +
']'
).hasClass( 'select2-hidden-accessible' )
) {
$(
'form.woocommerce-checkout [name=' +
checkout_data[ i ].name +
']'
).selectWoo( 'val', [ checkout_data[ i ].value ] );
} else {
$(
'form.woocommerce-checkout [name=' +
checkout_data[ i ].name +
']'
).val( checkout_data[ i ].value );
}
}
}
},
};
wcf_form_data.get();
$(
checkout_cust_form + ' input, ' + checkout_cust_form + ' select'
).on( 'change', function () {
wcf_form_data.set();
} );
};
const wcf_checkout_coupons = {
init() {
$( document.body ).on(
'click',
'.wcf-submit-coupon',
this.submit_coupon
);
$( document.body ).on(
'click',
'.wcf-remove-coupon',
this.remove_coupon
);
},
submit_coupon( e ) {
e.preventDefault();
const coupon_wrapper_class = $( '.wcf-custom-coupon-field' ),
coupon_wrapper = $( this ).closest( coupon_wrapper_class ),
coupon_field = coupon_wrapper.find( '.wcf-coupon-code-input' ),
coupon_value = coupon_field.val();
if ( '' === coupon_value ) {
coupon_field.addClass( 'field-required' );
return false;
}
coupon_field.removeClass( 'field-required' );
const billing_email = $(
'.wcf-embed-checkout-form #billing_email'
).val();
const data = {
coupon_code: coupon_value,
action: 'wcf_woo_apply_coupon',
security: cartflows.wcf_validate_coupon_nonce,
billing_email,
};
$.ajax( {
type: 'POST',
url: cartflows.ajax_url,
data,
success( code_data ) {
const coupon_message = $( '.wcf-custom-coupon-field' );
coupon_message
.find( '.woocommerce-error, .woocommerce-message' )
.remove();
if ( code_data && code_data.status === true ) {
$( document.body ).trigger( 'update_checkout', {
update_shipping_method: false,
} );
coupon_message.prepend( code_data.msg );
coupon_wrapper_class.addClass( 'wcf-coupon-applied' );
} else if ( code_data && code_data.msg ) {
coupon_message.prepend( code_data.msg );
coupon_wrapper_class.removeClass(
'wcf-coupon-applied'
);
} else {
console.log(
'Error: Error while applying the coupon. Response: ' +
code_data.data && code_data.data.error
? code_data.data.error
: code_data
);
}
},
} );
},
remove_coupon( e ) {
e.preventDefault();
const data = {
coupon_code: $( this ).attr( 'data-coupon' ),
action: 'wcf_woo_remove_coupon',
security: cartflows.wcf_validate_remove_coupon_nonce,
};
$.ajax( {
type: 'POST',
url: cartflows.ajax_url,
data,
success( code ) {
const coupon_message = $( '.wcf-custom-coupon-field' );
coupon_message
.find( '.woocommerce-error, .woocommerce-message' )
.hide();
$( '.wcf-custom-coupon-field' ).removeClass(
'wcf-coupon-applied'
);
if ( code ) {
$( document.body ).trigger( 'update_checkout', {
update_shipping_method: false,
} );
coupon_message.prepend( code );
}
},
} );
},
};
const wcf_remove_cart_products = function () {
$( document.body ).on(
'click',
'#wcf-embed-checkout-form .wcf-remove-product',
function ( e ) {
e.preventDefault();
const p_id = $( this ).attr( 'data-id' );
const data = {
p_key: $( this ).attr( 'data-item-key' ),
p_id,
action: 'wcf_woo_remove_cart_product',
security: cartflows.wcf_validate_remove_cart_product_nonce,
};
$.ajax( {
type: 'POST',
url: cartflows.ajax_url,
data,
success( response ) {
const res_data = JSON.parse( response );
if ( res_data.need_shipping === false ) {
// $('#wcf-embed-checkout-form').find('#ship-to-different-address-checkbox').hide();
$( '#wcf-embed-checkout-form' )
.find( '#ship-to-different-address-checkbox' )
.attr( 'checked', false );
}
$( '#wcf-embed-checkout-form' )
.find( '.woocommerce-notices-wrapper' )
.first()
.html( res_data.msg );
$( document ).trigger( 'cartflows_remove_product', [
p_id,
] );
$( '#wcf-embed-checkout-form' ).trigger(
'update_checkout'
);
},
} );
}
);
};
const wcf_toggle_optimized_fields = function () {
jQuery.each(
cartflows_checkout_optimized_fields,
function ( field, cartflows_optimized_field ) {
if ( cartflows_optimized_field.is_optimized ) {
jQuery( '#' + field ).prepend(
'' +
cartflows_optimized_field.field_label +
''
);
jQuery( '#wcf_optimized_' + field ).on(
'click',
function ( e ) {
e.preventDefault();
jQuery( '#' + field ).removeClass(
'wcf-hide-field'
);
// jQuery("#" + field).removeClass('mt20')
const field_id = field.replace( /_field/g, '' );
$( '#' + field_id ).trigger( 'focus' );
jQuery( this ).remove();
}
);
}
}
);
};
const wcf_instant_checkout_coupon_field = function () {
$( document.body ).on(
'click',
'.coupon-field .wcf-custom-coupon-field .wcf-optimized-coupon-field',
function ( e ) {
e.preventDefault();
$( '.wcf-custom-coupon-field' ).removeClass( 'wcf-hide-field' );
$( this ).remove();
}
);
};
const wcf_anim_field_style_two = function () {
const $inputs = $(
'.wcf-field-modern-label .woocommerce input, .wcf-field-modern-label .woocommerce select, .wcf-field-modern-label .woocommerce textarea'
);
/**
* Add wcf-anim-label class when floating label option is enabled.
* The class will be added only when the info is started to type in the checkout fields.
*
* @param {Object} $this the object of current checkout field
*/
const _add_anim_class = function ( $this ) {
const field_row = $this.closest( '.form-row' ),
is_select =
$this.is( 'select' ) ||
$this.hasClass( 'select2-hidden-accessible' ),
field_value = is_select
? $this.find( ':selected' ).text()
: $this.val(),
field_type = $this.attr( 'type' );
if ( '' === field_value ) {
field_row.removeClass( 'wcf-anim-label' );
} else if ( 'hidden' === field_type ) {
field_row.addClass( 'wcf-anim-hidden-label' );
} else {
field_row.addClass( 'wcf-anim-label' );
}
};
// Trigger the addition of anim class when focused or info is inputed on the field.
$inputs.on( 'focusout input', function () {
const $this = $( this );
_add_anim_class( $this );
} );
// Load the anim class on the page ready.
$( $inputs ).each( function () {
_add_anim_class( $( this ) );
} );
};
const validateEmail = function ( email ) {
const email_reg =
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return email_reg.test( email );
};
let xhrCountEmail = 0;
let delayTimerEmail;
const inline_email_address_validation = function () {
const email = $( '.wcf-customer-info #billing_email' ).val();
if ( 'undefined' === typeof email || cartflows.is_logged_in ) {
return;
}
if ( '' !== email ) {
const email_field = $( '#billing_email' );
const validation_msg_wrap = $( '.wcf-email-validation-block' ),
customer_login_wrap = $( '.wcf-customer-login-section' );
validation_msg_wrap.remove();
if ( ! validateEmail( email ) ) {
email_field.after(
'' +
cartflows.email_validation_msgs.error_msg +
''
);
customer_login_wrap.removeClass( 'wcf-show' );
return false;
}
clearTimeout( delayTimerEmail );
const seqNumber = ++xhrCountEmail;
delayTimerEmail = setTimeout( function () {
$.ajax( {
url: cartflows.ajax_url,
type: 'POST',
data: {
action: 'wcf_check_email_exists',
email_address: email,
security: cartflows.check_email_exist_nonce,
},
success( resp ) {
if ( seqNumber !== xhrCountEmail ) {
return;
}
validation_msg_wrap.remove();
if (
resp.data &&
resp.data.success &&
customer_login_wrap.hasClass( 'wcf-show' )
) {
email_field.after(
'' +
cartflows.email_validation_msgs
.success_msg +
''
);
return;
}
if ( resp.data && resp.data.success ) {
if ( resp.data.is_login_allowed ) {
email_field.after(
'' +
cartflows.email_validation_msgs
.success_msg +
''
);
customer_login_wrap
.slideDown( 400 )
.addClass( 'wcf-show' );
}
$( '.wcf-create-account-section' ).hide();
$(
'.woocommerce-billing-fields__customer-login-label'
).show();
} else {
customer_login_wrap
.slideUp( 400 )
.removeClass( 'wcf-show' );
//Learndash Woo integration plugin hides the create aacount checkbox.So need to show it again.
$(
'.wcf-create-account-section .create-account label.checkbox'
).show();
$( '.wcf-create-account-section' ).show();
$(
'.woocommerce-billing-fields__customer-login-label'
).hide();
}
},
} );
}, 300 );
} else {
$( '.wcf-create-account-section' ).hide();
$( '.wcf-customer-login-section' ).hide();
$( '.wcf-email-validation-block' ).hide();
$( '.woocommerce-billing-fields__customer-login-label' ).show();
}
return false;
};
const woocommerce_user_login = function () {
$( '.wcf-customer-login-url' ).on( 'click', function login_form( e ) {
e.preventDefault();
const customer_login_wrap = $( '.wcf-customer-login-section' );
if ( customer_login_wrap.hasClass( 'wcf-show' ) ) {
customer_login_wrap.slideUp( 400 );
customer_login_wrap.removeClass( 'wcf-show' );
} else {
customer_login_wrap.slideDown( 400 );
customer_login_wrap.addClass( 'wcf-show' );
}
} );
$( '.wcf-customer-login-section__login-button' ).on(
'click',
function name() {
const email = $( '#billing_email' ).val();
const password = $( '#billing_password' ).val();
$.ajax( {
url: cartflows.ajax_url,
type: 'POST',
data: {
action: 'wcf_woocommerce_login',
email,
password,
security: cartflows.woocommerce_login_nonce,
},
success( resp ) {
if ( resp.data && resp.data.success ) {
location.reload();
} else {
$( '.wcf-customer-info__notice' )
.addClass( 'wcf-notice' )
.html( resp.data.error );
}
},
} );
}
);
};
const wcf_instant_checkout_relocate_notices = function () {
if ( $( 'body' ).hasClass( 'cartflows-instant-checkout' ) ) {
$( '.woocommerce-NoticeGroup' ).prependTo(
'.woocommerce-notices-wrapper'
);
}
};
$( function () {
wcf_persistent_data();
wcf_update_checkout_on_return();
wcf_custom_field_validation();
wcf_remove_cart_products();
wcf_checkout_coupons.init();
wcf_toggle_optimized_fields();
wcf_instant_checkout_coupon_field();
$( document.body ).on(
'checkout_error updated_checkout',
wcf_instant_checkout_relocate_notices
);
wcf_anim_field_style_two();
// On email input field change.
$( '.wcf-customer-info #billing_email' ).on( 'input', function () {
inline_email_address_validation();
} );
// On page load as we saves the checkout fields values.
if ( $( '.wcf-customer-info #billing_email' ).length > 0 ) {
inline_email_address_validation();
}
woocommerce_user_login();
} );
} )( jQuery );
;
( function ( $ ) {
const wcf_page_title_notification = {
vars: {
originalTitle: document.title,
interval: null,
},
On( notification, intervalSpeed ) {
const _this = this;
_this.vars.interval = setInterval(
function () {
document.title =
_this.vars.originalTitle === document.title
? notification
: _this.vars.originalTitle;
},
intervalSpeed ? intervalSpeed : 1000
);
},
Off() {
clearInterval( this.vars.interval );
document.title = this.vars.originalTitle;
},
};
const wcf_update_product_options_cart_item_key = function () {
$( document ).on(
'wcf_cart_data_restored',
function ( e, wcf_cart_data ) {
if ( 'yes' === cartflows.is_product_options && wcf_cart_data ) {
$( '.wcf-qty-row' ).each( function () {
const product_data = $( this ).data( 'options' );
if ( product_data ) {
if ( product_data.unique_id in wcf_cart_data ) {
product_data.cart_item_key =
wcf_cart_data[ product_data.unique_id ];
$( this ).attr(
'data-options',
JSON.stringify( product_data )
);
}
}
} );
}
}
);
};
const wcf_animate_browser_tab = function () {
if ( 'yes' !== cartflows_animate_tab_fields.enabled ) {
return;
}
$( window ).blur( function () {
wcf_page_title_notification.On(
cartflows_animate_tab_fields.title
);
} );
$( window ).on( 'focus', function () {
wcf_page_title_notification.Off();
} );
};
// Scroll to top for the two step navigation.
const wcf_scroll_to_top = function ( scrollTo ) {
if ( scrollTo.length ) {
event.preventDefault();
$( 'html, body' )
.stop()
.animate(
{
scrollTop: scrollTo.offset().top - 50,
},
100
);
}
};
const wcf_display_spinner = function () {
$(
'.woocommerce-checkout-review-order-table, .wcf-product-option-wrap, .wcf-bump-order-wrap'
).block( {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6,
},
} );
};
const wcf_remove_spinner = function ( rsp ) {
if ( ! cartflows.wcf_refresh_checkout ) {
if ( jQuery( '.wc_payment_methods' ).length ) {
if ( rsp.hasOwnProperty( 'cart_total' ) ) {
// Update the Fragements for order bump & product options add/remove.
if ( rsp.hasOwnProperty( 'fragments' ) ) {
$.each( rsp.fragments, function ( key, value ) {
// Update the Fragments for place order button to update the cart price displayed on button.
if ( '#place_order' === key ) {
const selected_payment_gateway = $(
".wc_payment_methods input[name='payment_method']:checked"
);
if ( selected_payment_gateway.length > 0 ) {
$( key ).replaceWith( value );
const selected_payment_method = selected_payment_gateway.val();
if (
'ppcp-gateway' ===
selected_payment_method ||
'ppcp' === selected_payment_method
) {
$( key ).addClass( 'ppcp-hidden' );
}
selected_payment_gateway.trigger( 'click' );
}
} else {
$( key ).replaceWith( value );
}
} );
}
if ( parseFloat( rsp.cart_total ) > 0 ) {
/**
* Universal trigger just like update_checkout but of CartFlows.
* This trigger will be trigger after Order Bump, product options, quantity update in processes.
*/
$( 'body' ).trigger( 'cartflows_update_checkout' );
$(
'.woocommerce-checkout-review-order-table, .wcf-product-option-wrap, .wcf-bump-order-wrap'
).unblock();
} else {
$( 'body' ).trigger( 'update_checkout' );
$(
'.woocommerce-checkout-review-order-table, .wcf-product-option-wrap, .wcf-bump-order-wrap'
).unblock();
}
}
} else {
$( 'body' ).trigger( 'update_checkout' );
$(
'.woocommerce-checkout-review-order-table, .wcf-product-option-wrap, .wcf-bump-order-wrap'
).unblock();
}
} else {
$( 'body' ).trigger( 'update_checkout' );
$(
'.woocommerce-checkout-review-order-table, .wcf-product-option-wrap, .wcf-bump-order-wrap'
).unblock();
}
};
/**
* Re-calculate the cart total by triggering 'updated_cart_totals' trigger.
*/
const wcf_re_calculate_totals = function () {
// Re-calculate the cart total
$( document.body ).trigger( 'updated_cart_totals' );
};
const wcf_product_quantity_var_options = function () {
const wcf_variation_validation_trigger_click = function () {
$( 'form.woocommerce-checkout' ).on(
'checkout_place_order',
function ( e ) {
const invalid_var = $(
'.wcf-select-variation-attribute.wcf-invalid-variation'
);
if ( invalid_var.length > 0 ) {
e.preventDefault();
wcf_scroll_to_top( invalid_var );
return ! 1;
}
}
);
$( '.wcf-select-variation-attribute' ).on( 'click', function ( e ) {
e.preventDefault();
const wrap = $( this ).closest( '.wcf-qty-row' );
wrap.find( '.wcf-item-choose-options a' ).trigger( 'click' );
} );
};
$( '.wcf-qty-row' ).on( 'click', function ( event ) {
if (
$( event.target ).is(
'.wcf-multiple-sel, .wcf-single-sel, .wcf-qty, .wcf-qty-selection, .wcf-variable-item-popup-text, .wcf-qty-selection-btn, .wcf-qty-increment-icon, .wcf-qty-decrement-icon'
)
) {
return;
}
const single_selection = $( this ).find( '.wcf-single-sel' ),
multiple_selection = $( this ).find( '.wcf-multiple-sel' );
if ( single_selection.length > 0 ) {
single_selection.trigger( 'click' );
} else if ( multiple_selection.length > 0 ) {
multiple_selection.trigger( 'click' );
}
} );
/* Single Selection */
$( document ).on( 'change', '.wcf-single-sel', function () {
const $this = $( this );
const wrapper = $this.closest( '.wcf-qty-options' );
const wrap = $this.closest( '.wcf-qty-row' );
const option = wrap.data( 'options' );
const input = wrap.find( '.wcf-qty input' );
let input_quantity = parseInt( input.val() );
const checkout_id = $( '._wcf_checkout_id' ).val();
if ( 0 >= input_quantity || isNaN( input_quantity ) ) {
input.val( 1 );
input_quantity = 1;
}
option.input_quantity = input_quantity;
option.checkout_id = checkout_id;
const post_data = $( 'form.checkout' ).serialize();
wcf_display_spinner();
wrapper.addClass( 'wcf-loading' );
$.ajax( {
url: cartflows.ajax_url,
data: {
action: 'wcf_single_selection',
option,
post_data,
security: cartflows.wcf_single_selection_nonce,
},
dataType: 'json',
type: 'POST',
success( response ) {
if ( response.hasOwnProperty( 'cartflows_data' ) ) {
wrap.find( '.wcf-display-quantity' ).html(
response.cartflows_data.display_quantity
);
wrap.find( '.wcf-display-price' ).html(
response.cartflows_data.display_price
);
wrap.find( '.wcf-display-discount-value' ).html(
response.cartflows_data.display_discount_value
);
wrap.find( '.wcf-display-discount-percent' ).html(
response.cartflows_data.display_discount_percent
);
wrap.find( '.wcf_subscription_price' ).html(
response.cartflows_data.subscription_price
);
wrap.find( '.wcf_subscription_fee' ).html(
response.cartflows_data.sign_up_fee
);
console.log( response );
}
wcf_remove_spinner( response );
wrapper.removeClass( 'wcf-loading' );
option.cart_item_key = response.cart_item_key;
wrap.attr( 'data-options', JSON.stringify( option ) );
// Re-calculate the cart total
wcf_re_calculate_totals();
},
error() {
$( '.woocommerce-checkout-review-order-table' ).unblock();
},
} );
} );
/* Multiple Selection */
$( document ).on( 'change', '.wcf-multiple-sel', function () {
const checked_cb = $( '.wcf-multiple-sel:checked' );
const $this = $( this );
const wrap = $this.closest( '.wcf-qty-row' );
const input = wrap.find( '.wcf-qty input' );
let input_quantity = parseInt( input.val() );
if ( 0 >= input_quantity || isNaN( input_quantity ) ) {
input.val( 1 );
input_quantity = 1;
}
if ( 0 === checked_cb.length ) {
$this.prop( 'checked', true );
$this.prop( 'disabled', true );
return;
}
if ( 1 === checked_cb.length ) {
checked_cb.prop( 'disabled', true );
} else {
checked_cb.removeAttr( 'disabled' );
}
const option = wrap.data( 'options' );
const checkout_id = $( '._wcf_checkout_id' ).val();
option.checkout_id = checkout_id;
option.input_quantity = input_quantity;
option.checked = 'no';
const post_data = $( 'form.checkout' ).serialize();
if ( $this.is( ':checked' ) ) {
option.checked = 'yes';
}
wcf_display_spinner();
$( '.wcf-qty-options' ).addClass( 'wcf-loading' );
$.ajax( {
url: cartflows.ajax_url,
data: {
action: 'wcf_multiple_selection',
option,
post_data,
security: cartflows.wcf_multiple_selection_nonce,
},
dataType: 'json',
type: 'POST',
success( response ) {
if ( response.hasOwnProperty( 'cartflows_data' ) ) {
wrap.find( '.wcf-display-quantity' ).html(
response.cartflows_data.display_quantity
);
wrap.find( '.wcf-display-price' ).html(
response.cartflows_data.display_price
);
wrap.find( '.wcf-display-discount-value' ).html(
response.cartflows_data.display_discount_value
);
wrap.find( '.wcf-display-discount-percent' ).html(
response.cartflows_data.display_discount_percent
);
wrap.find( '.wcf_subscription_price' ).html(
response.cartflows_data.subscription_price
);
wrap.find( '.wcf_subscription_fee' ).html(
response.cartflows_data.sign_up_fee
);
}
wcf_remove_spinner( response );
$( '.wcf-qty-options' ).removeClass( 'wcf-loading' );
option.cart_item_key = response.cart_item_key;
wrap.attr( 'data-options', JSON.stringify( option ) );
// Re-calculate the cart total
wcf_re_calculate_totals();
},
error() {
$( '.woocommerce-checkout-review-order-table' ).unblock();
},
} );
} );
/* Force All Selection */
$( document ).on( 'change', '.wcf-var-sel', function () {
const $this = $( this );
const wrap = $this.closest( '.wcf-qty-row' );
const input = wrap.find( '.wcf-qty input' );
const option = wrap.data( 'options' );
const input_quantity = parseInt( input.val() );
const checkout_id = $( '._wcf_checkout_id' ).val();
option.checkout_id = checkout_id;
option.input_quantity = input_quantity;
wcf_display_spinner();
$( '.wcf-qty-options' ).addClass( 'wcf-loading' );
$.ajax( {
url: cartflows.ajax_url,
data: {
action: 'wcf_variation_selection',
option,
security: cartflows.wcf_variation_selection_nonce,
},
dataType: 'json',
type: 'POST',
success( response ) {
if ( response.hasOwnProperty( 'cartflows_data' ) ) {
wrap.find( '.wcf-display-quantity' ).html(
response.cartflows_data.display_quantity
);
wrap.find( '.wcf-display-price' ).html(
response.cartflows_data.display_price
);
wrap.find( '.wcf-display-discount-value' ).html(
response.cartflows_data.display_discount_value
);
wrap.find( '.wcf-display-discount-percent' ).html(
response.cartflows_data.display_discount_percent
);
wrap.find( '.wcf_subscription_price' ).html(
response.cartflows_data.subscription_price
);
wrap.find( '.wcf_subscription_fee' ).html(
response.cartflows_data.sign_up_fee
);
}
wcf_remove_spinner( response );
$( '.wcf-qty-options' ).removeClass( 'wcf-loading' );
// Re-calculate the cart total
wcf_re_calculate_totals();
},
error() {
$( '.woocommerce-checkout-review-order-table' ).unblock();
},
} );
} );
/* Quantity Selection For All type */
$( document ).on( 'change', '.wcf-qty-selection', function () {
const $this = $( this ),
wrap = $this.closest( '.wcf-qty-row' ),
item_selector = wrap.find( '.wcf-item-selector' );
if ( item_selector.length > 0 ) {
const selector_input = item_selector.find( 'input' );
if (
selector_input.length > 0 &&
! selector_input.is( ':checked' )
) {
return;
}
}
const is_sold_individually = Boolean( $this.data( 'sale-limit' ) );
// Skip the ajax call if the sold individual option is enabled for the selected product OR a variation.
if ( is_sold_individually ) {
return;
}
const option = wrap.data( 'options' ),
checkout_id = $( '._wcf_checkout_id' ).val();
let input_quantity = parseInt( $this.val() );
if ( 0 >= input_quantity || isNaN( input_quantity ) ) {
$this.val( 1 );
input_quantity = 1;
}
option.input_quantity = input_quantity;
option.checkout_id = checkout_id;
const post_data = $( 'form.checkout' ).serialize();
if ( typeof data !== 'undefined' ) {
option.cart_item_key = data.cart_item_key;
}
wcf_display_spinner();
$( '.wcf-qty-options' ).addClass( 'wcf-loading' );
$.ajax( {
url: cartflows.ajax_url,
data: {
action: 'wcf_quantity_update',
option,
post_data,
security: cartflows.wcf_quantity_update_nonce,
},
dataType: 'json',
type: 'POST',
success( response ) {
if ( response.hasOwnProperty( 'cartflows_data' ) ) {
wrap.find( '.wcf-display-quantity' ).html(
response.cartflows_data.display_quantity
);
wrap.find( '.wcf-display-price' ).html(
response.cartflows_data.display_price
);
wrap.find( '.wcf-display-discount-value' ).html(
response.cartflows_data.display_discount_value
);
wrap.find( '.wcf-display-discount-percent' ).html(
response.cartflows_data.display_discount_percent
);
wrap.find( '.wcf_subscription_price' ).html(
response.cartflows_data.subscription_price
);
wrap.find( '.wcf_subscription_fee' ).html(
response.cartflows_data.sign_up_fee
);
}
wcf_remove_spinner( response );
$( '.wcf-qty-options' ).removeClass( 'wcf-loading' );
// Re-calculate the cart total
wcf_re_calculate_totals();
},
error() {
$( '.woocommerce-checkout-review-order-table' ).unblock();
},
} );
} );
/* Variation attribute and click trigger */
wcf_variation_validation_trigger_click();
/* Variation Popup */
wcf_quick_view();
};
const wcf_do_not_remove_single_product = function () {
const checked_cb = $( '.wcf-multiple-sel:checked' );
if ( 1 === checked_cb.length ) {
checked_cb.prop( 'checked', true );
checked_cb.prop( 'disabled', true );
}
};
const wcf_remove_product = function () {
$( document ).on( 'cartflows_remove_product', function ( e, p_id ) {
jQuery( '.wcf-multiple-sel[value="' + p_id + '"]' ).prop(
'checked',
false
);
jQuery( '.wcf-single-sel[value="' + p_id + '"]' ).prop(
'checked',
false
);
} );
};
const wcf_order_bump_ajax = function () {
let wcf_order_bump_clicked = false;
$( document ).on( 'change', '.wcf-bump-order-cb', function () {
if ( true === wcf_order_bump_clicked ) {
return false;
}
wcf_order_bump_clicked = true;
const $this = $( this );
const product_id = $this.data( 'ob_data' ).product_id;
const checkout_id = $( '[name=_wcf_checkout_id]' ).val();
const bump_offer_data = $this.attr( 'data-ob_data' ),
ob_id = $this.data( 'ob_data' ).ob_id;
const bump_offer_qty = $this
.closest( '.wcf-bump-order-content' )
.find( '.wcf-order-bump-quantity-updater' )
.val();
const button_class = $this
.closest( '.wcf-bump-order-field-wrap' )
.find( '.wcf-bump-order-cb-button' );
const bump_offer_wrap = $this.closest( '.wcf-bump-order-wrap' );
let is_add_to_cart = '';
const data = {
post_data: $( 'form.checkout' ).serialize(),
security: cartflows.wcf_bump_order_process_nonce,
_wcf_checkout_id: checkout_id,
_wcf_product_id: product_id,
_bump_offer_data: bump_offer_data ? bump_offer_data : '',
_bump_offer_qty: bump_offer_qty > 0 ? bump_offer_qty : '',
action: 'wcf_bump_order_process',
};
let bump_product_ids = $( '[name=_wcf_bump_products]' ).val();
if ( '' === bump_product_ids ) {
bump_product_ids = {};
} else {
bump_product_ids = JSON.parse( bump_product_ids );
}
if ( $this.is( ':checked' ) ) {
data._wcf_bump_product_action = 'add_bump_product';
is_add_to_cart = true;
} else {
data._wcf_bump_product_action = 'remove_bump_product';
is_add_to_cart = false;
}
// Display spinner for specific order bump.
bump_offer_wrap.block( {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6,
},
} );
$.ajax( {
url: cartflows.ajax_url,
data,
dataType: 'json',
type: 'POST',
success( response ) {
wcf_remove_spinner( response );
if ( button_class.length > 0 ) {
if ( is_add_to_cart ) {
button_class.toggleClass(
'wcf-bump-add-to-cart wcf-bump-remove-from-cart'
);
button_class.text( $this.data( 'remove' ) );
} else {
button_class.toggleClass(
'wcf-bump-remove-from-cart wcf-bump-add-to-cart'
);
button_class.text( $this.data( 'add' ) );
}
}
if ( $this.is( ':checked' ) ) {
bump_product_ids[ ob_id ] = {
id: product_id,
price: response.cartflows_data.total_product_price,
};
} else {
delete bump_product_ids[ ob_id ];
}
$( '[name=_wcf_bump_products]' ).val(
JSON.stringify( bump_product_ids )
);
// Re-calculate the cart total
wcf_re_calculate_totals();
},
error() {
$( '.woocommerce-checkout-review-order-table' ).unblock();
},
} );
wcf_order_bump_clicked = false;
return false;
} );
};
const wcf_nav_tab_hide_show_events = function () {
/* Ready */
wcf_nav_tab_hide_show();
$( '.wcf-embed-checkout-form-two-step .woocommerce' ).addClass(
'step-one'
);
/* Change Custom Field*/
$(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-steps a'
).on( 'click', function ( e ) {
e.preventDefault();
wcf_nav_tab_hide_show();
} );
/* Change on click of next button */
$(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-nav-btns a'
).on( 'click', function ( e ) {
e.preventDefault();
// Check form validation before go to step two.
wcf_nav_tab_hide_show_next_btn();
} );
};
const wcf_nav_tab_hide_show_next_btn = function () {
if ( wcf_two_step_validations() ) {
$(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-steps div.wcf-current'
).removeClass( 'wcf-current' );
const selector = $(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-nav-btns a'
).attr( 'href' );
if ( selector === '#customer_details' ) {
wcf_scroll_to_top( $( '.wcf-embed-checkout-form-nav' ) );
$(
'.wcf-embed-checkout-form-two-step .woocommerce'
).removeClass( 'step-two' );
$( '.wcf-embed-checkout-form-two-step .woocommerce' ).addClass(
'step-one'
);
$( '.wcf-embed-checkout-form-two-step' )
.find( '.step-one' )
.addClass( 'wcf-current' );
} else if ( selector === '#wcf-order-wrap' ) {
wcf_scroll_to_top( $( '.wcf-embed-checkout-form-nav' ) );
$(
'.wcf-embed-checkout-form-two-step .woocommerce'
).removeClass( 'step-one' );
$( '.wcf-embed-checkout-form-two-step .woocommerce' ).addClass(
'step-two'
);
$( '.wcf-embed-checkout-form-two-step' )
.find( '.step-two' )
.addClass( 'wcf-current' );
}
}
};
const wcf_nav_tab_hide_show = function () {
$(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-steps a'
).on( 'click', function ( e ) {
e.preventDefault();
// Check form validation before go to step two.
// if ( $("div").hasClass("wcf-embed-checkout-form-two-step") && ! $('form[name="checkout"]').valid() ) {
// return false;
// }
if ( wcf_two_step_validations() ) {
const $this = $( this ),
wrap = $this.closest(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-steps div'
);
// validated = wcf_woocommerce_field_validate();
// if(validated === false){
// return false;
// }
$(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-steps div.wcf-current'
).removeClass( 'wcf-current' );
wrap.addClass( 'wcf-current' );
const selector = $this
.closest(
'.wcf-embed-checkout-form-two-step .wcf-embed-checkout-form-steps div a'
)
.attr( 'href' );
if ( selector === '#customer_details' ) {
$(
'.wcf-embed-checkout-form-two-step .woocommerce'
).removeClass( 'step-two' );
$(
'.wcf-embed-checkout-form-two-step .woocommerce'
).addClass( 'step-one' );
} else if ( selector === '#wcf-order-wrap' ) {
$(
'.wcf-embed-checkout-form-two-step .woocommerce'
).removeClass( 'step-one' );
$(
'.wcf-embed-checkout-form-two-step .woocommerce'
).addClass( 'step-two' );
}
}
} );
};
/* Autocomplete Zip Code */
const wcf_autocomplete_zip_data = function () {
let zip_code_timeout;
$( document.body ).on(
'textInput input change keypress paste',
'#billing_postcode, #shipping_postcode',
function () {
const $this = $( this ),
type = $this.attr( 'id' ).split( '_' )[ 0 ],
country = $( '#' + type + '_country' ).val();
if ( '' === country ) {
return;
}
const zip_code = $this.val().trim();
if ( '' === zip_code ) {
return;
}
clearTimeout( zip_code_timeout );
zip_code_timeout = setTimeout( function () {
if ( -1 === [ 'GB', 'CA' ].indexOf( country ) ) {
get_zip_data_and_update( type, country, zip_code );
}
}, 800 );
}
);
const get_zip_data_and_update = function ( type, country, zip_code ) {
$.ajax( {
url: 'https://api.zippopotam.us/' + country + '/' + zip_code,
cache: ! 0,
dataType: 'json',
type: 'GET',
success( result ) {
$.each( result.places, function () {
$( '#' + type + '_city' )
.val( this[ 'place name' ] )
.trigger( 'change' );
$( '[name="' + type + '_state"]:visible' )
.val( this[ 'state abbreviation' ] )
.trigger( 'change' );
return false;
} );
},
error() {},
} );
};
};
/**
* Quick View
*/
const wcf_quick_view = function () {
const quick_view_btn = $( '.wcf-item-choose-options a' );
const modal_wrap = $( '.wcf-quick-view-wrapper' );
modal_wrap.appendTo( document.body );
const wcf_quick_view_bg = modal_wrap.find( '.wcf-quick-view-bg' ),
wcf_qv_modal = modal_wrap.find( '#wcf-quick-view-modal' ),
wcf_qv_content = wcf_qv_modal.find( '#wcf-quick-view-content' ),
wcf_qv_close_btn = wcf_qv_modal.find( '#wcf-quick-view-close' ),
wcf_qv_wrapper = wcf_qv_modal.find( '.wcf-content-main-wrapper' );
quick_view_btn.off( 'click' ).on( 'click', function ( e ) {
e.preventDefault();
const $this = $( this );
/* Check if product is selected */
const cls_wrap = $this.closest( '.wcf-item' );
if (
! cls_wrap.find( '.wcf-item-selector input' ).is( ':checked' )
) {
cls_wrap.find( '.wcf-item-selector input' ).trigger( 'click' );
}
const product_id = $this.data( 'product' );
$this.addClass( 'wcf-variation-popup-open' );
if ( ! wcf_qv_modal.hasClass( 'loading' ) ) {
wcf_qv_modal.addClass( 'loading' );
}
if ( ! wcf_quick_view_bg.hasClass( 'wcf-quick-view-bg-ready' ) ) {
wcf_quick_view_bg.addClass( 'wcf-quick-view-bg-ready' );
}
$( document ).trigger( 'wcf_quick_view_loading' );
wcf_qv_ajax_call( $this, product_id );
} );
const wcf_qv_ajax_call = function ( t, product_id ) {
wcf_qv_modal.css( 'opacity', 0 );
$.ajax( {
url: cartflows.ajax_url,
data: {
action: 'wcf_woo_quick_view',
product_id,
},
dataType: 'html',
type: 'POST',
success( data ) {
wcf_qv_content.html( data );
wcf_qv_content_height();
},
} );
};
const wcf_qv_content_height = function () {
// Variation Form
const form_variation = wcf_qv_content.find( '.variations_form' );
form_variation.trigger( 'check_variations' );
form_variation.trigger( 'reset_image' );
if ( ! wcf_qv_modal.hasClass( 'open' ) ) {
wcf_qv_modal.removeClass( 'loading' ).addClass( 'open' );
const scrollbar_width = wcf_get_scrollbar_width();
const $html = $( 'html' );
$html.css( 'margin-right', scrollbar_width );
$html.addClass( 'wcf-quick-view-is-open' );
}
if (
form_variation.length > 0 &&
'function' === typeof form_variation.wc_variation_form
) {
form_variation.wc_variation_form();
form_variation.find( 'select' ).trigger( 'change' );
}
/*wcf_qv_content.imagesLoaded( function(e) {
var image_slider_wrap = wcf_qv_modal.find('.wcf-qv-image-slider');
if ( image_slider_wrap.find('li').length > 1 ) {
image_slider_wrap.flexslider({
animation: "slide",
start: function( slider ){
setTimeout(function() {
wcf_update_summary_height( true );
}, 300);
},
});
}else{
setTimeout(function() {
wcf_update_summary_height( true );
}, 300);
}
});*/
const image_slider_wrap = wcf_qv_modal.find(
'.wcf-qv-image-slider'
);
if ( image_slider_wrap.find( 'li' ).length > 1 ) {
image_slider_wrap.flexslider( {
animation: 'slide',
start() {
setTimeout( function () {
wcf_update_summary_height( true );
}, 300 );
},
} );
} else {
setTimeout( function () {
wcf_update_summary_height( true );
}, 300 );
}
// Add trrigger to slide back to the varations selected image while in flexslider.
$( document ).on(
'woocommerce_gallery_reset_slide_position',
function () {
// Varations image is always replaced at the first index of the slider.
image_slider_wrap.flexslider( 0 );
}
);
// stop loader
$( document ).trigger( 'wcf_quick_view_loader_stop' );
};
const wcf_qv_close_modal = function () {
// Close box by click overlay
wcf_qv_wrapper.on( 'click', function ( e ) {
if ( this === e.target ) {
wcf_qv_close();
}
} );
// Close box with esc key
$( document ).on( 'keyup', function ( e ) {
if ( e.keyCode === 27 ) {
wcf_qv_close();
}
} );
// Close box by click close button
wcf_qv_close_btn.on( 'click', function ( e ) {
e.preventDefault();
wcf_qv_close();
} );
const wcf_qv_close = function () {
wcf_quick_view_bg.removeClass( 'wcf-quick-view-bg-ready' );
wcf_qv_modal.removeClass( 'open' ).removeClass( 'loading' );
$( 'html' ).removeClass( 'wcf-quick-view-is-open' );
$( 'html' ).css( 'margin-right', '' );
quick_view_btn.removeClass( 'wcf-variation-popup-open' );
setTimeout( function () {
wcf_qv_content.html( '' );
}, 600 );
};
};
/*var ast_qv_center_modal = function() {
ast_qv_wrapper.css({
'width' : '',
'height' : ''
});
ast_qv_wrapper_w = ast_qv_wrapper.width(),
ast_qv_wrapper_h = ast_qv_wrapper.height();
var window_w = $(window).width(),
window_h = $(window).height(),
width = ( ( window_w - 60 ) > ast_qv_wrapper_w ) ? ast_qv_wrapper_w : ( window_w - 60 ),
height = ( ( window_h - 120 ) > ast_qv_wrapper_h ) ? ast_qv_wrapper_h : ( window_h - 120 );
ast_qv_wrapper.css({
'left' : (( window_w/2 ) - ( width/2 )),
'top' : (( window_h/2 ) - ( height/2 )),
'width' : width + 'px',
'height' : height + 'px'
});
};
*/
const wcf_update_summary_height = function ( update_css ) {
const quick_view = wcf_qv_content,
img_height = quick_view
.find( '.product .wcf-qv-image-slider' )
.first()
.height(),
summary = quick_view.find( '.product .summary.entry-summary' ),
content = summary.css( 'content' );
if (
'undefined' !== typeof content &&
544 === content.replace( /[^0-9]/g, '' ) &&
0 !== img_height &&
null !== img_height
) {
summary.css( 'height', img_height );
} else {
summary.css( 'height', '' );
}
if ( true === update_css ) {
wcf_qv_modal.css( 'opacity', 1 );
}
};
const wcf_get_scrollbar_width = function () {
const div = $(
''
);
// 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 ) {
console.log( 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 = quantity_input.attr( 'min' );
if ( $( e.target ).hasClass( 'wcf-qty-increment' ) ) {
quantity_input.val( val + 1 );
} else {
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.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 );
;