2014-03-19 03:42:53 +00:00
|
|
|
jQuery( function( $ ) {
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2014-02-17 12:09:35 +00:00
|
|
|
$.blockUI.defaults.overlayCSS.cursor = 'default';
|
|
|
|
|
2013-12-04 19:15:24 +00:00
|
|
|
// wc_checkout_params is required to continue, ensure the object exists
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( typeof wc_checkout_params === 'undefined' )
|
2013-12-04 19:15:24 +00:00
|
|
|
return false;
|
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
var updateTimer,
|
|
|
|
dirtyInput = false,
|
|
|
|
xhr;
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
function update_checkout() {
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( xhr ) xhr.abort();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2013-08-14 20:00:34 +00:00
|
|
|
var shipping_methods = [];
|
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function( index, input ) {
|
|
|
|
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
|
2013-08-14 20:00:34 +00:00
|
|
|
} );
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
var payment_method = $( '#order_review input[name=payment_method]:checked' ).val(),
|
|
|
|
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,
|
|
|
|
s_state,
|
|
|
|
s_postcode,
|
|
|
|
s_city,
|
|
|
|
s_address,
|
|
|
|
s_address_2;
|
|
|
|
|
|
|
|
if ( $( '#ship-to-different-address input' ).is( ':checked' ) || $( '#ship-to-different-address input' ).size() === 0 ) {
|
|
|
|
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();
|
2013-05-28 13:19:08 +00:00
|
|
|
} else {
|
2014-03-19 03:42:53 +00:00
|
|
|
s_country = country;
|
|
|
|
s_state = state;
|
|
|
|
s_postcode = postcode;
|
|
|
|
s_city = city;
|
|
|
|
s_address = address;
|
|
|
|
s_address_2 = address_2;
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( '#order_methods, #order_review' ).block({ message: null, overlayCSS: { background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
var data = {
|
2014-03-19 03:42:53 +00:00
|
|
|
action: 'woocommerce_update_order_review',
|
|
|
|
security: wc_checkout_params.update_order_review_nonce,
|
|
|
|
shipping_method: shipping_methods,
|
|
|
|
payment_method: 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,
|
|
|
|
post_data: $( 'form.checkout' ).serialize()
|
2012-07-17 14:09:18 +00:00
|
|
|
};
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
xhr = $.ajax({
|
2014-03-19 03:42:53 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: wc_checkout_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
success: function( response ) {
|
2012-10-17 11:43:59 +00:00
|
|
|
if ( response ) {
|
2014-04-24 14:08:38 +00:00
|
|
|
$( '#order_review' ).html( $.trim( response ) );
|
2014-03-24 11:02:05 +00:00
|
|
|
$( '#order_review' ).find( 'input[name=payment_method]:checked' ).trigger('click');
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' ).trigger('updated_checkout' );
|
2012-10-17 11:43:59 +00:00
|
|
|
}
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
// Event for updating the checkout
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' ).bind( 'update_checkout', function() {
|
|
|
|
clearTimeout( updateTimer );
|
2012-07-17 14:09:18 +00:00
|
|
|
update_checkout();
|
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'p.password, form.login, .checkout_coupon, div.shipping_address' ).hide();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'input.show_password' ).change( function() {
|
|
|
|
$( 'p.password' ).slideToggle();
|
2012-07-17 14:09:18 +00:00
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'a.showlogin' ).click( function() {
|
|
|
|
$( 'form.login' ).slideToggle();
|
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'a.showcoupon' ).click( function() {
|
|
|
|
$( '.checkout_coupon' ).slideToggle( 400, function() {
|
|
|
|
$( '#coupon_code' ).focus();
|
2013-08-06 08:36:28 +00:00
|
|
|
});
|
2014-03-19 03:42:53 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( '#ship-to-different-address input' ).change( function() {
|
|
|
|
$( 'div.shipping_address' ).hide();
|
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( 'div.shipping_address' ).slideDown();
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
|
|
|
}).change();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( wc_checkout_params.option_guest_checkout === 'yes' ) {
|
|
|
|
|
|
|
|
$( 'div.create-account' ).hide();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'input#createaccount' ).change( function() {
|
|
|
|
$( 'div.create-account' ).hide();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( 'div.create-account' ).slideDown();
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
|
|
|
}).change();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( '#order_review' )
|
2012-12-28 13:02:12 +00:00
|
|
|
|
|
|
|
/* Payment option selection */
|
|
|
|
|
|
|
|
.on( 'click', '.payment_methods input.input-radio', function() {
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( $( '.payment_methods input.input-radio' ).length > 1 ) {
|
|
|
|
var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) );
|
|
|
|
|
|
|
|
if ( $( this ).is( ':checked' ) && ! target_payment_box.is( ':visible' ) ) {
|
|
|
|
$( 'div.payment_box' ).filter( ':visible' ).slideUp( 250 );
|
|
|
|
|
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( 'div.payment_box.' + $( this ).attr( 'ID' ) ).slideDown( 250 );
|
2014-01-20 15:18:47 +00:00
|
|
|
}
|
2012-10-08 02:01:43 +00:00
|
|
|
}
|
2012-11-07 21:23:45 +00:00
|
|
|
} else {
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'div.payment_box' ).show();
|
2012-11-07 21:23:45 +00:00
|
|
|
}
|
2014-03-19 03:42:53 +00:00
|
|
|
|
|
|
|
if ( $( this ).data( 'order_button_text' ) ) {
|
|
|
|
$( '#place_order' ).val( $( this ).data( 'order_button_text' ) );
|
2014-01-28 11:25:52 +00:00
|
|
|
} else {
|
2014-03-19 03:42:53 +00:00
|
|
|
$( '#place_order' ).val( $( '#place_order' ).data( 'value' ) );
|
2014-01-28 11:25:52 +00:00
|
|
|
}
|
2013-02-05 10:46:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Trigger initial click
|
2014-03-19 03:42:53 +00:00
|
|
|
.find( 'input[name=payment_method]:checked' ).click();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-04-07 11:42:54 +00:00
|
|
|
// Used for input change events below
|
|
|
|
function input_changed() {
|
|
|
|
var update_totals = true;
|
|
|
|
|
|
|
|
if ( $( dirtyInput ).size() ) {
|
|
|
|
|
|
|
|
$required_inputs = $( dirtyInput ).closest( 'div' ).find( '.address-field.validate-required' );
|
|
|
|
|
|
|
|
if ( $required_inputs.size() ) {
|
|
|
|
$required_inputs.each( function() {
|
|
|
|
if ( $( this ).find( 'input.input-text' ).val() === '' ) {
|
|
|
|
update_totals = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( update_totals ) {
|
|
|
|
dirtyInput = false;
|
|
|
|
$( 'body' ).trigger( 'update_checkout' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'form.checkout' )
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2013-01-20 15:36:25 +00:00
|
|
|
/* Update totals/taxes/shipping */
|
2012-07-20 12:46:05 +00:00
|
|
|
// Inputs/selects which update totals instantly
|
2014-03-19 03:42:53 +00:00
|
|
|
.on( 'input change', 'select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select', function() {
|
2012-07-17 14:09:18 +00:00
|
|
|
clearTimeout( updateTimer );
|
2013-01-20 15:36:25 +00:00
|
|
|
dirtyInput = false;
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' ).trigger( 'update_checkout' );
|
2012-12-28 13:02:12 +00:00
|
|
|
})
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2013-01-20 15:36:25 +00:00
|
|
|
// Address-fields which refresh totals when all required fields are filled
|
2014-04-07 11:42:54 +00:00
|
|
|
.on( 'change', '.address-field input.input-text, .update_totals_on_change input.input-text', function() {
|
2012-07-20 12:46:05 +00:00
|
|
|
if ( dirtyInput ) {
|
2013-01-20 15:36:25 +00:00
|
|
|
input_changed();
|
2012-07-20 12:46:05 +00:00
|
|
|
}
|
2012-12-28 13:02:12 +00:00
|
|
|
})
|
2013-01-20 15:36:25 +00:00
|
|
|
|
2013-07-21 09:38:17 +00:00
|
|
|
.on( 'input change', '.address-field select', function() {
|
2013-01-20 15:36:25 +00:00
|
|
|
dirtyInput = this;
|
|
|
|
input_changed();
|
|
|
|
})
|
|
|
|
|
2014-04-07 11:42:54 +00:00
|
|
|
.on( 'input keydown', '.address-field input.input-text, .update_totals_on_change input.input-text', function( e ){
|
|
|
|
var code = e.keyCode || e.which || 0;
|
2014-03-19 03:42:53 +00:00
|
|
|
|
2014-04-07 11:42:54 +00:00
|
|
|
if ( code === 9 ) {
|
|
|
|
return true;
|
2014-03-19 03:42:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 15:36:25 +00:00
|
|
|
dirtyInput = this;
|
2012-07-20 12:46:05 +00:00
|
|
|
clearTimeout( updateTimer );
|
|
|
|
updateTimer = setTimeout( input_changed, '1000' );
|
2012-12-28 13:02:12 +00:00
|
|
|
})
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-12-10 14:50:49 +00:00
|
|
|
/* Inline validation */
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2013-07-21 09:38:17 +00:00
|
|
|
.on( 'blur input change', '.input-text, select', function() {
|
2014-03-19 03:42:53 +00:00
|
|
|
var $this = $( this ),
|
|
|
|
$parent = $this.closest( '.form-row' ),
|
|
|
|
validated = true;
|
2012-12-10 14:50:49 +00:00
|
|
|
|
|
|
|
if ( $parent.is( '.validate-required' ) ) {
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( $this.val() === '' ) {
|
2013-01-03 11:40:10 +00:00
|
|
|
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' );
|
2012-12-10 14:50:49 +00:00
|
|
|
validated = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $parent.is( '.validate-email' ) ) {
|
|
|
|
if ( $this.val() ) {
|
|
|
|
|
|
|
|
/* http://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex */
|
|
|
|
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\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]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([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])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
|
|
|
|
|
|
|
|
if ( ! pattern.test( $this.val() ) ) {
|
2013-01-03 11:40:10 +00:00
|
|
|
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-email' );
|
2012-12-10 14:50:49 +00:00
|
|
|
validated = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( validated ) {
|
2013-01-03 11:40:10 +00:00
|
|
|
$parent.removeClass( 'woocommerce-invalid woocommerce-invalid-required-field' ).addClass( 'woocommerce-validated' );
|
2012-12-10 14:50:49 +00:00
|
|
|
}
|
2012-12-28 13:02:12 +00:00
|
|
|
} )
|
2012-12-10 14:50:49 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
/* AJAX Form Submission */
|
2012-12-28 13:02:12 +00:00
|
|
|
|
|
|
|
.submit( function() {
|
2012-07-20 12:46:05 +00:00
|
|
|
clearTimeout( updateTimer );
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
var $form = $( this );
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( $form.is( '.processing' ) ) {
|
2012-07-17 14:09:18 +00:00
|
|
|
return false;
|
2014-03-19 03:42:53 +00:00
|
|
|
}
|
2012-07-17 14:09:18 +00:00
|
|
|
|
|
|
|
// Trigger a handler to let gateways manipulate the checkout if needed
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( $form.triggerHandler( 'checkout_place_order' ) !== false && $form.triggerHandler( 'checkout_place_order_' + $( '#order_review input[name=payment_method]:checked' ).val() ) !== false ) {
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$form.addClass( 'processing' );
|
2012-07-17 14:09:18 +00:00
|
|
|
|
|
|
|
var form_data = $form.data();
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( form_data["blockUI.isBlocked"] != 1 ) {
|
|
|
|
$form.block({ message: null, overlayCSS: { background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
|
|
|
|
}
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
$.ajax({
|
2014-03-19 03:42:53 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: wc_checkout_params.checkout_url,
|
|
|
|
data: $form.serialize(),
|
|
|
|
success: function( code ) {
|
2013-09-04 10:26:19 +00:00
|
|
|
var result = '';
|
2013-09-02 16:43:53 +00:00
|
|
|
|
2013-09-04 10:26:19 +00:00
|
|
|
try {
|
|
|
|
// Get the valid JSON only from the returned string
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( code.indexOf( '<!--WC_START-->' ) >= 0 )
|
|
|
|
code = code.split( '<!--WC_START-->' )[1]; // Strip off before after WC_START
|
2013-03-08 12:24:22 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( code.indexOf( '<!--WC_END-->' ) >= 0 )
|
|
|
|
code = code.split( '<!--WC_END-->' )[0]; // Strip off anything after WC_END
|
2012-12-13 16:59:33 +00:00
|
|
|
|
2013-09-04 10:26:19 +00:00
|
|
|
// Parse
|
|
|
|
result = $.parseJSON( code );
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( result.result === 'success' ) {
|
|
|
|
window.location = decodeURI( result.redirect );
|
|
|
|
} else if ( result.result === 'failure' ) {
|
|
|
|
throw 'Result failure';
|
2013-09-04 10:26:19 +00:00
|
|
|
} else {
|
2014-03-19 03:42:53 +00:00
|
|
|
throw 'Invalid response';
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
2013-09-04 10:26:19 +00:00
|
|
|
}
|
2014-03-19 03:42:53 +00:00
|
|
|
|
2013-09-04 10:26:19 +00:00
|
|
|
catch( err ) {
|
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( result.reload === 'true' ) {
|
2013-09-04 10:26:19 +00:00
|
|
|
window.location.reload();
|
|
|
|
return;
|
2012-07-17 14:09:18 +00:00
|
|
|
}
|
2013-09-04 10:26:19 +00:00
|
|
|
|
|
|
|
// Remove old errors
|
2014-03-19 03:42:53 +00:00
|
|
|
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
2013-09-04 10:26:19 +00:00
|
|
|
|
|
|
|
// Add new errors
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( result.messages ) {
|
2013-09-04 10:26:19 +00:00
|
|
|
$form.prepend( result.messages );
|
2014-03-19 03:42:53 +00:00
|
|
|
} else {
|
2013-09-04 10:26:19 +00:00
|
|
|
$form.prepend( code );
|
2014-03-19 03:42:53 +00:00
|
|
|
}
|
2013-09-04 10:26:19 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
// Cancel processing
|
|
|
|
$form.removeClass( 'processing' ).unblock();
|
2013-09-04 10:26:19 +00:00
|
|
|
|
|
|
|
// Lose focus for all fields
|
|
|
|
$form.find( '.input-text, select' ).blur();
|
|
|
|
|
|
|
|
// Scroll to top
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'html, body' ).animate({
|
|
|
|
scrollTop: ( $( 'form.checkout' ).offset().top - 100 )
|
|
|
|
}, 1000 );
|
2013-09-04 10:26:19 +00:00
|
|
|
|
|
|
|
// Trigger update in case we need a fresh nonce
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( result.refresh === 'true' )
|
|
|
|
$( 'body' ).trigger( 'update_checkout' );
|
2013-09-16 13:55:17 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' ).trigger( 'checkout_error' );
|
2013-09-04 10:26:19 +00:00
|
|
|
}
|
|
|
|
},
|
2014-03-19 03:42:53 +00:00
|
|
|
dataType: 'html'
|
2012-07-17 14:09:18 +00:00
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-28 13:02:12 +00:00
|
|
|
return false;
|
2013-02-05 10:46:31 +00:00
|
|
|
});
|
2012-12-28 13:02:12 +00:00
|
|
|
|
|
|
|
/* AJAX Coupon Form Submission */
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'form.checkout_coupon' ).submit( function() {
|
|
|
|
var $form = $( this );
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
if ( $form.is( '.processing' ) ) return false;
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$form.addClass( 'processing' ).block({ message: null, overlayCSS: {background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
|
2012-12-28 13:02:12 +00:00
|
|
|
|
|
|
|
var data = {
|
2014-03-19 03:42:53 +00:00
|
|
|
action: 'woocommerce_apply_coupon',
|
|
|
|
security: wc_checkout_params.apply_coupon_nonce,
|
|
|
|
coupon_code: $form.find( 'input[name=coupon_code]' ).val()
|
2012-12-28 13:02:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
2014-03-19 03:42:53 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: wc_checkout_params.ajax_url,
|
|
|
|
data: data,
|
|
|
|
success: function( code ) {
|
|
|
|
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
|
|
|
$form.removeClass( 'processing' ).unblock();
|
2012-12-28 13:02:12 +00:00
|
|
|
|
|
|
|
if ( code ) {
|
|
|
|
$form.before( code );
|
|
|
|
$form.slideUp();
|
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' ).trigger( 'update_checkout' );
|
2012-12-28 13:02:12 +00:00
|
|
|
}
|
|
|
|
},
|
2014-03-19 03:42:53 +00:00
|
|
|
dataType: 'html'
|
2012-12-28 13:02:12 +00:00
|
|
|
});
|
2014-03-19 03:42:53 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' )
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2012-09-03 15:45:09 +00:00
|
|
|
// Init trigger
|
2014-03-19 03:42:53 +00:00
|
|
|
.bind( 'init_checkout', function() {
|
|
|
|
$( '#billing_country, #shipping_country, .country_to_state' ).change();
|
|
|
|
$( 'body' ).trigger( 'update_checkout' );
|
2012-09-03 15:45:09 +00:00
|
|
|
});
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2012-09-03 15:45:09 +00:00
|
|
|
// Update on page load
|
2014-03-28 20:46:33 +00:00
|
|
|
if ( wc_checkout_params.is_checkout === '1' ) {
|
2014-03-19 03:42:53 +00:00
|
|
|
$( 'body' ).trigger( 'init_checkout' );
|
2013-03-26 12:22:59 +00:00
|
|
|
}
|
2012-12-10 11:06:14 +00:00
|
|
|
|
2013-06-13 04:28:46 +00:00
|
|
|
});
|