2014-03-18 03:08:41 +00:00
|
|
|
jQuery( function( $ ) {
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2013-12-04 19:15:24 +00:00
|
|
|
// wc_cart_params is required to continue, ensure the object exists
|
2014-03-18 03:08:41 +00:00
|
|
|
if ( typeof wc_cart_params === 'undefined' ) {
|
2013-12-04 19:15:24 +00:00
|
|
|
return false;
|
2014-03-18 03:08:41 +00:00
|
|
|
}
|
2013-12-04 19:15:24 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
// Shipping calculator
|
2014-03-18 03:08:41 +00:00
|
|
|
$( document ).on( 'click', '.shipping-calculator-button', function() {
|
|
|
|
$( '.shipping-calculator-form' ).slideToggle( 'slow' );
|
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
return false;
|
2014-01-16 07:06:23 +00:00
|
|
|
}).on( 'change', 'select.shipping_method, input[name^=shipping_method]', function() {
|
2013-08-14 20:00:34 +00:00
|
|
|
|
|
|
|
var shipping_methods = [];
|
|
|
|
|
2014-03-18 03:08:41 +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-28 13:02:12 +00:00
|
|
|
|
2014-11-14 11:52:44 +00:00
|
|
|
$( 'div.cart_totals' ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
var data = {
|
2014-03-18 03:08:41 +00:00
|
|
|
action: 'woocommerce_update_shipping_method',
|
|
|
|
security: wc_cart_params.update_shipping_method_nonce,
|
|
|
|
shipping_method: shipping_methods
|
2012-07-17 14:09:18 +00:00
|
|
|
};
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2014-03-18 03:08:41 +00:00
|
|
|
$.post( wc_cart_params.ajax_url, data, function( response ) {
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2014-03-18 03:08:41 +00:00
|
|
|
$( 'div.cart_totals' ).replaceWith( response );
|
|
|
|
$( 'body' ).trigger( 'updated_shipping_method' );
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2012-07-17 14:09:18 +00:00
|
|
|
});
|
2014-03-18 03:08:41 +00:00
|
|
|
});
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2014-03-18 03:08:41 +00:00
|
|
|
$( '.shipping-calculator-form' ).hide();
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2013-12-04 19:15:24 +00:00
|
|
|
});
|