queue remove from cart

This commit is contained in:
Mike Jolley 2019-04-12 12:05:07 +01:00
parent e9836ef298
commit 2f9d6ac669
1 changed files with 19 additions and 9 deletions

View File

@ -15,10 +15,10 @@ jQuery( function( $ ) {
$( document.body ) $( document.body )
.on( 'click', '.add_to_cart_button', { addToCartHandler: this }, this.onAddToCart ) .on( 'click', '.add_to_cart_button', { addToCartHandler: this }, this.onAddToCart )
.on( 'click', '.remove_from_cart_button', this.onRemoveFromCart ) .on( 'click', '.remove_from_cart_button', { addToCartHandler: this }, this.onRemoveFromCart )
.on( 'added_to_cart', this.updateButton ) .on( 'added_to_cart', this.updateButton )
.on( 'added_to_cart', this.updateCartPage ) .on( 'added_to_cart', this.updateCartPage )
.on( 'added_to_cart removed_from_cart', this.updateFragments ); .on( 'added_to_cart removed_from_cart', { addToCartHandler: this }, this.updateFragments );
}; };
/** /**
@ -123,15 +123,25 @@ jQuery( function( $ ) {
} }
}); });
$.post( wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'remove_from_cart' ), { cart_item_key : $thisbutton.data( 'cart_item_key' ) }, function( response ) { e.data.addToCartHandler.addRequest({
if ( ! response || ! response.fragments ) { type: 'POST',
url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'remove_from_cart' ),
data: {
cart_item_key : $thisbutton.data( 'cart_item_key' )
},
success: function( response ) {
if ( ! response || ! response.fragments ) {
window.location = $thisbutton.attr( 'href' );
return;
}
$( document.body ).trigger( 'removed_from_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
},
error: function() {
window.location = $thisbutton.attr( 'href' ); window.location = $thisbutton.attr( 'href' );
return; return;
} },
$( document.body ).trigger( 'removed_from_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); dataType: 'json'
}).fail( function() {
window.location = $thisbutton.attr( 'href' );
return;
}); });
}; };