2015-06-10 17:26:21 +00:00
|
|
|
/* global wc_cart_params */
|
2014-03-18 03:08:41 +00:00
|
|
|
jQuery( function( $ ) {
|
2012-07-17 14:09:18 +00:00
|
|
|
|
2016-02-15 04:55:47 +00:00
|
|
|
// wc_cart_params is required to continue, ensure the object exists
|
|
|
|
if ( typeof wc_cart_params === 'undefined' ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-19 20:26:27 +00:00
|
|
|
// Utility functions for the file.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a url for a given AJAX endpoint.
|
|
|
|
*
|
|
|
|
* @param {String} endpoint The AJAX Endpoint
|
|
|
|
* @return {String} The URL to use for the request
|
|
|
|
*/
|
2016-02-11 20:13:01 +00:00
|
|
|
var get_url = function( endpoint ) {
|
|
|
|
return wc_cart_params.wc_ajax_url.toString().replace(
|
|
|
|
'%%endpoint%%',
|
|
|
|
endpoint
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2016-02-19 20:26:27 +00:00
|
|
|
/**
|
|
|
|
* Check if a node is blocked for processing.
|
|
|
|
*
|
|
|
|
* @param {JQuery Object} $node
|
|
|
|
* @return {bool} True if the DOM Element is UI Blocked, false if not.
|
|
|
|
*/
|
2016-02-11 19:01:20 +00:00
|
|
|
var is_blocked = function( $node ) {
|
2016-06-24 11:18:31 +00:00
|
|
|
return $node.is( '.processing' ) || $node.parents( '.processing' ).length;
|
2016-02-11 19:01:20 +00:00
|
|
|
};
|
|
|
|
|
2016-02-19 20:26:27 +00:00
|
|
|
/**
|
|
|
|
* Block a node visually for processing.
|
|
|
|
*
|
|
|
|
* @param {JQuery Object} $node
|
|
|
|
*/
|
2016-02-11 19:01:20 +00:00
|
|
|
var block = function( $node ) {
|
2016-06-24 11:18:31 +00:00
|
|
|
if ( ! is_blocked( $node ) ) {
|
|
|
|
$node.addClass( 'processing' ).block( {
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2016-02-11 19:01:20 +00:00
|
|
|
};
|
|
|
|
|
2016-02-19 20:26:27 +00:00
|
|
|
/**
|
|
|
|
* Unblock a node after processing is complete.
|
|
|
|
*
|
|
|
|
* @param {JQuery Object} $node
|
|
|
|
*/
|
2016-02-11 19:01:20 +00:00
|
|
|
var unblock = function( $node ) {
|
|
|
|
$node.removeClass( 'processing' ).unblock();
|
|
|
|
};
|
|
|
|
|
2016-02-19 20:26:27 +00:00
|
|
|
/**
|
|
|
|
* Update the .woocommerce div with a string of html.
|
|
|
|
*
|
|
|
|
* @param {String} html_str The HTML string with which to replace the div.
|
|
|
|
*/
|
2016-02-15 04:55:47 +00:00
|
|
|
var update_wc_div = function( html_str ) {
|
2016-06-01 11:45:14 +00:00
|
|
|
var $html = $.parseHTML( html_str );
|
2016-06-27 10:42:28 +00:00
|
|
|
var $new_form = $( '.shop_table.cart', $html ).closest( 'form' );
|
2016-06-01 11:45:14 +00:00
|
|
|
var $new_totals = $( '.cart_totals', $html );
|
2016-04-08 17:02:45 +00:00
|
|
|
|
2016-05-03 16:03:43 +00:00
|
|
|
// Error message collection
|
|
|
|
var $error = $( '.woocommerce-error', $html );
|
|
|
|
var $message = $( '.woocommerce-message', $html );
|
|
|
|
|
|
|
|
// Remove errors
|
|
|
|
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
|
|
|
|
2016-04-20 04:36:48 +00:00
|
|
|
if ( $new_form.length === 0 ) {
|
2016-06-27 10:42:28 +00:00
|
|
|
// If the checkout is also displayed on this page, trigger reload instead.
|
|
|
|
if ( $( '.woocommerce-checkout' ).length ) {
|
|
|
|
window.location.reload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-20 10:21:32 +00:00
|
|
|
// No items to display now! Replace all cart content.
|
|
|
|
var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' );
|
2016-06-27 10:42:28 +00:00
|
|
|
$( '.shop_table.cart' ).closest( '.woocommerce' ).replaceWith( $cart_html );
|
2016-05-03 16:03:43 +00:00
|
|
|
|
2016-06-27 10:42:28 +00:00
|
|
|
// Display errors
|
2016-05-03 16:03:43 +00:00
|
|
|
if ( $error.length > 0 ) {
|
|
|
|
show_notice( $error, $( '.cart-empty' ).closest( '.woocommerce' ) );
|
|
|
|
} else if ( $message.length > 0 ) {
|
|
|
|
show_notice( $message, $( '.cart-empty' ).closest( '.woocommerce' ) );
|
|
|
|
}
|
2016-04-20 04:36:48 +00:00
|
|
|
} else {
|
2016-06-27 10:42:28 +00:00
|
|
|
// If the checkout is also displayed on this page, trigger update event.
|
|
|
|
if ( $( '.woocommerce-checkout' ).length ) {
|
|
|
|
$( document.body ).trigger( 'update_checkout' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '.shop_table.cart' ).closest( 'form' ).replaceWith( $new_form );
|
|
|
|
$( '.shop_table.cart' ).closest( 'form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', true );
|
2016-04-20 10:21:32 +00:00
|
|
|
|
|
|
|
if ( $error.length > 0 ) {
|
|
|
|
show_notice( $error );
|
|
|
|
} else if ( $message.length > 0 ) {
|
|
|
|
show_notice( $message );
|
|
|
|
}
|
2016-06-15 14:51:53 +00:00
|
|
|
|
|
|
|
update_cart_totals_div( $new_totals );
|
2016-04-20 04:36:48 +00:00
|
|
|
}
|
2016-06-01 11:45:14 +00:00
|
|
|
|
|
|
|
$( document.body ).trigger( 'updated_wc_div' );
|
2016-02-15 04:55:47 +00:00
|
|
|
};
|
2013-12-04 19:15:24 +00:00
|
|
|
|
2016-06-15 14:51:53 +00:00
|
|
|
/**
|
|
|
|
* Update the .cart_totals div with a string of html.
|
|
|
|
*
|
|
|
|
* @param {String} html_str The HTML string with which to replace the div.
|
|
|
|
*/
|
|
|
|
var update_cart_totals_div = function( html_str ) {
|
|
|
|
$( '.cart_totals' ).replaceWith( html_str );
|
|
|
|
$( document.body ).trigger( 'updated_cart_totals' );
|
|
|
|
};
|
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
/**
|
|
|
|
* Clear previous notices and shows new one above form.
|
|
|
|
*
|
|
|
|
* @param {Object} The Notice HTML Element in string or object form.
|
|
|
|
*/
|
2016-05-03 16:03:43 +00:00
|
|
|
var show_notice = function( html_element, $target ) {
|
|
|
|
if ( ! $target ) {
|
2016-06-27 10:42:28 +00:00
|
|
|
$target = $( '.shop_table.cart' ).closest( 'form' );
|
2016-05-03 16:03:43 +00:00
|
|
|
}
|
2016-02-22 16:15:47 +00:00
|
|
|
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
2016-05-03 16:03:43 +00:00
|
|
|
$target.before( html_element );
|
2016-02-22 16:15:47 +00:00
|
|
|
};
|
|
|
|
|
2016-02-19 20:13:48 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-19 20:33:28 +00:00
|
|
|
* Object to handle AJAX calls for cart shipping changes.
|
2016-02-19 20:13:48 +00:00
|
|
|
*/
|
2016-02-19 20:33:28 +00:00
|
|
|
var cart_shipping = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize event handlers and UI state.
|
|
|
|
*/
|
2016-04-19 17:55:36 +00:00
|
|
|
init: function( cart ) {
|
|
|
|
this.cart = cart;
|
2016-02-22 16:15:47 +00:00
|
|
|
this.toggle_shipping = this.toggle_shipping.bind( this );
|
|
|
|
this.shipping_method_selected = this.shipping_method_selected.bind( this );
|
|
|
|
this.shipping_calculator_submit = this.shipping_calculator_submit.bind( this );
|
|
|
|
|
2016-02-19 20:33:28 +00:00
|
|
|
$( document ).on(
|
|
|
|
'click',
|
|
|
|
'.shipping-calculator-button',
|
|
|
|
this.toggle_shipping
|
|
|
|
);
|
|
|
|
$( document ).on(
|
|
|
|
'change',
|
|
|
|
'select.shipping_method, input[name^=shipping_method]',
|
|
|
|
this.shipping_method_selected
|
|
|
|
);
|
|
|
|
$( document ).on(
|
|
|
|
'submit',
|
|
|
|
'form.woocommerce-shipping-calculator',
|
|
|
|
this.shipping_calculator_submit
|
|
|
|
);
|
|
|
|
|
|
|
|
$( '.shipping-calculator-form' ).hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle Shipping Calculator panel
|
|
|
|
*/
|
|
|
|
toggle_shipping: function() {
|
|
|
|
$( '.shipping-calculator-form' ).slideToggle( 'slow' );
|
|
|
|
return false;
|
|
|
|
},
|
2016-02-19 20:13:48 +00:00
|
|
|
|
2016-02-19 20:33:28 +00:00
|
|
|
/**
|
|
|
|
* Handles when a shipping method is selected.
|
|
|
|
*
|
|
|
|
* @param {Object} evt The JQuery event.
|
|
|
|
*/
|
|
|
|
shipping_method_selected: function( evt ) {
|
2016-06-15 17:02:58 +00:00
|
|
|
var target = evt.currentTarget;
|
2013-08-14 20:00:34 +00:00
|
|
|
|
2016-05-24 00:34:43 +00:00
|
|
|
var shipping_methods = {};
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2016-02-19 20:33:28 +00:00
|
|
|
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function() {
|
|
|
|
shipping_methods[ $( target ).data( 'index' ) ] = $( target ).val();
|
|
|
|
} );
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2016-02-19 20:33:28 +00:00
|
|
|
block( $( 'div.cart_totals' ) );
|
2012-12-28 13:02:12 +00:00
|
|
|
|
2016-02-19 20:33:28 +00:00
|
|
|
var data = {
|
|
|
|
security: wc_cart_params.update_shipping_method_nonce,
|
|
|
|
shipping_method: shipping_methods
|
|
|
|
};
|
2016-02-15 16:52:25 +00:00
|
|
|
|
2016-06-15 14:51:53 +00:00
|
|
|
$.ajax( {
|
|
|
|
type: 'post',
|
|
|
|
url: get_url( 'update_shipping_method' ),
|
|
|
|
data: data,
|
|
|
|
dataType: 'html',
|
|
|
|
success: function( response ) {
|
|
|
|
update_cart_totals_div( response );
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
unblock( $( 'div.cart_totals' ) );
|
|
|
|
$( document.body ).trigger( 'updated_shipping_method' );
|
|
|
|
}
|
2016-02-19 20:33:28 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a shipping calculator form submit.
|
|
|
|
*
|
|
|
|
* @param {Object} evt The JQuery event.
|
|
|
|
*/
|
|
|
|
shipping_calculator_submit: function( evt ) {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
2016-06-15 17:02:58 +00:00
|
|
|
var $form = $( evt.currentTarget );
|
2016-02-19 20:33:28 +00:00
|
|
|
|
2016-06-01 11:45:14 +00:00
|
|
|
block( $( 'div.cart_totals' ) );
|
2016-06-24 11:18:31 +00:00
|
|
|
block( $form );
|
2016-02-19 20:33:28 +00:00
|
|
|
|
|
|
|
// Provide the submit button value because wc-form-handler expects it.
|
|
|
|
$( '<input />' ).attr( 'type', 'hidden' )
|
2016-06-15 14:51:53 +00:00
|
|
|
.attr( 'name', 'calc_shipping' )
|
|
|
|
.attr( 'value', 'x' )
|
|
|
|
.appendTo( $form );
|
2016-02-19 20:33:28 +00:00
|
|
|
|
|
|
|
// Make call to actual form post URL.
|
|
|
|
$.ajax( {
|
|
|
|
type: $form.attr( 'method' ),
|
|
|
|
url: $form.attr( 'action' ),
|
|
|
|
data: $form.serialize(),
|
|
|
|
dataType: 'html',
|
|
|
|
success: function( response ) {
|
2016-06-01 11:45:14 +00:00
|
|
|
update_wc_div( response );
|
2016-02-19 20:33:28 +00:00
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
unblock( $form );
|
2016-06-01 11:45:14 +00:00
|
|
|
unblock( $( 'div.cart_totals' ) );
|
2016-02-19 20:33:28 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2016-02-19 20:13:48 +00:00
|
|
|
};
|
|
|
|
|
2016-02-19 20:26:27 +00:00
|
|
|
/**
|
2016-02-22 16:15:47 +00:00
|
|
|
* Object to handle cart UI.
|
2016-02-19 20:26:27 +00:00
|
|
|
*/
|
2016-02-22 16:15:47 +00:00
|
|
|
var cart = {
|
|
|
|
/**
|
|
|
|
* Initialize cart UI events.
|
|
|
|
*/
|
|
|
|
init: function() {
|
2016-06-01 11:45:14 +00:00
|
|
|
this.update_cart_totals = this.update_cart_totals.bind( this );
|
|
|
|
this.cart_submit = this.cart_submit.bind( this );
|
|
|
|
this.submit_click = this.submit_click.bind( this );
|
|
|
|
this.apply_coupon = this.apply_coupon.bind( this );
|
2016-02-22 16:15:47 +00:00
|
|
|
this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
|
2016-06-01 11:45:14 +00:00
|
|
|
this.quantity_update = this.quantity_update.bind( this );
|
|
|
|
this.item_remove_clicked = this.item_remove_clicked.bind( this );
|
|
|
|
this.update_cart = this.update_cart.bind( this );
|
2016-02-11 06:26:41 +00:00
|
|
|
|
2016-06-01 11:45:14 +00:00
|
|
|
$( document ).on(
|
|
|
|
'wc_update_cart',
|
|
|
|
this.update_cart );
|
2016-05-02 20:26:14 +00:00
|
|
|
$( document ).on(
|
|
|
|
'click',
|
|
|
|
'div.woocommerce > form input[type=submit]',
|
|
|
|
this.submit_click );
|
2016-02-22 16:15:47 +00:00
|
|
|
$( document ).on(
|
|
|
|
'submit',
|
|
|
|
'div.woocommerce > form',
|
|
|
|
this.cart_submit );
|
|
|
|
$( document ).on(
|
|
|
|
'click',
|
|
|
|
'a.woocommerce-remove-coupon',
|
|
|
|
this.remove_coupon_clicked );
|
|
|
|
$( document ).on(
|
|
|
|
'click',
|
|
|
|
'td.product-remove > a',
|
|
|
|
this.item_remove_clicked );
|
2016-04-20 10:10:39 +00:00
|
|
|
$( document ).on(
|
|
|
|
'change input',
|
|
|
|
'div.woocommerce > form .cart_item :input',
|
|
|
|
this.input_changed );
|
|
|
|
|
|
|
|
$( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', true );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-05-02 20:26:14 +00:00
|
|
|
* After an input is changed, enable the update cart button.
|
2016-04-20 10:10:39 +00:00
|
|
|
*/
|
|
|
|
input_changed: function() {
|
|
|
|
$( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', false );
|
2016-02-22 16:15:47 +00:00
|
|
|
},
|
|
|
|
|
2016-06-01 11:45:14 +00:00
|
|
|
/**
|
|
|
|
* Update entire cart via ajax.
|
|
|
|
*/
|
|
|
|
update_cart: function() {
|
2016-06-27 10:42:28 +00:00
|
|
|
var $form = $( '.shop_table.cart' ).closest( 'form' );
|
2016-06-01 11:45:14 +00:00
|
|
|
|
|
|
|
block( $form );
|
|
|
|
block( $( 'div.cart_totals' ) );
|
|
|
|
|
|
|
|
// Make call to actual form post URL.
|
|
|
|
$.ajax( {
|
|
|
|
type: $form.attr( 'method' ),
|
|
|
|
url: $form.attr( 'action' ),
|
|
|
|
data: $form.serialize(),
|
|
|
|
dataType: 'html',
|
|
|
|
success: function( response ) {
|
|
|
|
update_wc_div( response );
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
unblock( $form );
|
|
|
|
unblock( $( 'div.cart_totals' ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
/**
|
|
|
|
* Update the cart after something has changed.
|
|
|
|
*/
|
|
|
|
update_cart_totals: function() {
|
|
|
|
block( $( 'div.cart_totals' ) );
|
|
|
|
|
|
|
|
$.ajax( {
|
|
|
|
url: get_url( 'get_cart_totals' ),
|
|
|
|
dataType: 'html',
|
2016-06-15 14:51:53 +00:00
|
|
|
success: function( response ) {
|
|
|
|
update_cart_totals_div( response );
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
unblock( $( 'div.cart_totals' ) );
|
2016-02-22 16:15:47 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle cart form submit and route to correct logic.
|
|
|
|
*
|
|
|
|
* @param {Object} evt The JQuery event
|
|
|
|
*/
|
|
|
|
cart_submit: function( evt ) {
|
2016-06-15 17:02:58 +00:00
|
|
|
var $form = $( evt.currentTarget );
|
2016-02-22 16:15:47 +00:00
|
|
|
var $submit = $( document.activeElement );
|
2016-05-02 20:26:14 +00:00
|
|
|
var $clicked = $( 'input[type=submit][clicked=true]' );
|
2016-02-22 16:15:47 +00:00
|
|
|
|
2016-06-27 10:42:28 +00:00
|
|
|
if ( 0 === $form.find( '.shop_table.cart' ).length ) {
|
2016-04-06 17:14:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-22 16:15:47 +00:00
|
|
|
if ( is_blocked( $form ) ) {
|
|
|
|
return false;
|
2016-02-11 06:26:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-02 20:26:14 +00:00
|
|
|
if ( $clicked.is( '[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) {
|
2016-06-15 19:13:46 +00:00
|
|
|
evt.preventDefault();
|
2016-02-22 16:15:47 +00:00
|
|
|
this.quantity_update( $form );
|
2016-02-11 18:51:29 +00:00
|
|
|
|
2016-05-02 20:26:14 +00:00
|
|
|
} else if ( $clicked.is( '[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) {
|
2016-06-15 19:13:46 +00:00
|
|
|
evt.preventDefault();
|
2016-02-22 16:15:47 +00:00
|
|
|
this.apply_coupon( $form );
|
|
|
|
}
|
|
|
|
},
|
2016-02-11 18:51:29 +00:00
|
|
|
|
2016-05-02 20:26:14 +00:00
|
|
|
/**
|
|
|
|
* Special handling to identify which submit button was clicked.
|
|
|
|
*
|
|
|
|
* @param {Object} evt The JQuery event
|
|
|
|
*/
|
|
|
|
submit_click: function( evt ) {
|
|
|
|
$( 'input[type=submit]', $( evt.target ).parents( 'form' ) ).removeAttr( 'clicked' );
|
|
|
|
$( evt.target ).attr( 'clicked', 'true' );
|
|
|
|
},
|
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
/**
|
|
|
|
* Apply Coupon code
|
|
|
|
*
|
|
|
|
* @param {JQuery Object} $form The cart form.
|
|
|
|
*/
|
|
|
|
apply_coupon: function( $form ) {
|
|
|
|
block( $form );
|
2016-02-11 06:26:41 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
var cart = this;
|
|
|
|
var $text_field = $( '#coupon_code' );
|
|
|
|
var coupon_code = $text_field.val();
|
2016-02-15 16:27:47 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
var data = {
|
|
|
|
security: wc_cart_params.apply_coupon_nonce,
|
|
|
|
coupon_code: coupon_code
|
|
|
|
};
|
2016-02-11 19:01:20 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
$.ajax( {
|
|
|
|
type: 'POST',
|
|
|
|
url: get_url( 'apply_coupon' ),
|
|
|
|
data: data,
|
|
|
|
dataType: 'html',
|
|
|
|
success: function( response ) {
|
|
|
|
show_notice( response );
|
2016-05-06 11:05:55 +00:00
|
|
|
$( document.body ).trigger( 'applied_coupon' );
|
2016-02-22 16:15:47 +00:00
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
unblock( $form );
|
|
|
|
$text_field.val( '' );
|
|
|
|
cart.update_cart_totals();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
2016-02-11 19:01:20 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
/**
|
|
|
|
* Handle when a remove coupon link is clicked.
|
|
|
|
*
|
|
|
|
* @param {Object} evt The JQuery event
|
|
|
|
*/
|
|
|
|
remove_coupon_clicked: function( evt ) {
|
|
|
|
evt.preventDefault();
|
2016-02-15 16:27:47 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
var cart = this;
|
2016-06-15 17:02:58 +00:00
|
|
|
var $tr = $( evt.currentTarget ).parents( 'tr' );
|
|
|
|
var coupon = $( evt.currentTarget ).attr( 'data-coupon' );
|
2016-02-15 16:27:47 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
block( $tr.parents( 'table' ) );
|
2016-02-11 19:55:34 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
var data = {
|
|
|
|
security: wc_cart_params.remove_coupon_nonce,
|
|
|
|
coupon: coupon
|
|
|
|
};
|
2016-02-15 03:57:14 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
$.ajax( {
|
|
|
|
type: 'POST',
|
|
|
|
url: get_url( 'remove_coupon' ),
|
|
|
|
data: data,
|
|
|
|
dataType: 'html',
|
|
|
|
success: function( response ) {
|
|
|
|
show_notice( response );
|
2016-05-09 15:39:21 +00:00
|
|
|
$( document.body ).trigger( 'removed_coupon' );
|
2016-02-22 16:15:47 +00:00
|
|
|
unblock( $tr.parents( 'table' ) );
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
cart.update_cart_totals();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
2016-02-15 04:55:47 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
/**
|
|
|
|
* Handle a cart Quantity Update
|
|
|
|
*
|
|
|
|
* @param {JQuery Object} $form The cart form.
|
|
|
|
*/
|
|
|
|
quantity_update: function( $form ) {
|
|
|
|
// Provide the submit button value because wc-form-handler expects it.
|
|
|
|
$( '<input />' ).attr( 'type', 'hidden' )
|
|
|
|
.attr( 'name', 'update_cart' )
|
|
|
|
.attr( 'value', 'Update Cart' )
|
|
|
|
.appendTo( $form );
|
2016-02-15 14:10:25 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
block( $form );
|
2016-06-01 11:45:14 +00:00
|
|
|
block( $( 'div.cart_totals' ) );
|
2016-02-19 20:13:48 +00:00
|
|
|
|
2016-02-22 16:15:47 +00:00
|
|
|
// Make call to actual form post URL.
|
|
|
|
$.ajax( {
|
|
|
|
type: $form.attr( 'method' ),
|
|
|
|
url: $form.attr( 'action' ),
|
|
|
|
data: $form.serialize(),
|
|
|
|
dataType: 'html',
|
|
|
|
success: update_wc_div,
|
|
|
|
complete: function() {
|
|
|
|
unblock( $form );
|
2016-06-01 11:45:14 +00:00
|
|
|
unblock( $( 'div.cart_totals' ) );
|
2016-02-22 16:15:47 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle when a remove item link is clicked.
|
|
|
|
*
|
|
|
|
* @param {Object} evt The JQuery event
|
|
|
|
*/
|
|
|
|
item_remove_clicked: function( evt ) {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
2016-06-15 17:02:58 +00:00
|
|
|
var $a = $( evt.currentTarget );
|
2016-02-22 16:15:47 +00:00
|
|
|
var $form = $a.parents( 'form' );
|
|
|
|
|
|
|
|
block( $form );
|
2016-06-01 11:45:14 +00:00
|
|
|
block( $( 'div.cart_totals' ) );
|
2016-02-22 16:15:47 +00:00
|
|
|
|
|
|
|
$.ajax( {
|
|
|
|
type: 'GET',
|
|
|
|
url: $a.attr( 'href' ),
|
|
|
|
dataType: 'html',
|
|
|
|
success: update_wc_div,
|
|
|
|
complete: function() {
|
|
|
|
unblock( $form );
|
2016-06-01 11:45:14 +00:00
|
|
|
unblock( $( 'div.cart_totals' ) );
|
2016-02-22 16:15:47 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
2016-02-19 20:33:28 +00:00
|
|
|
|
2016-04-19 17:55:36 +00:00
|
|
|
cart_shipping.init( cart );
|
2016-02-22 16:15:47 +00:00
|
|
|
cart.init();
|
2016-02-15 14:40:46 +00:00
|
|
|
} );
|