I am using fancy product designer for woocommerce (http://fancyproductdesigner.com/woocommerce-plugin/)
with this plugin a user can create a custom product design and add it to the cart. When viewing the cart there is a link to go back and edit their design. After editing the user hits add to cart again and it adds a NEW item to the cart instead of updating the current. The user then has to manually remove the old design from the cart themselves.
I created an ajax call when an item is being edited so when the “add to cart” link is clicked it does the following ajax call to remove the old item from the cart. Here is the ajax call below.
// if a user is editing an item. remove the old one on save.
$('.single_add_to_cart_button').click(function(evt) {
$.ajaxSetup({ cache: false });
if(options.editingFP) {
//$.get( options.removeCI.replace('&','&'), function( data ) { alert(data); });
$.ajax({
type: 'GET',
url: options.removeCI.replace('&','&'),
beforeSend:function(){
// this is where we append a loading image
alert('getting ready to send ajax call to remove item from cart');
},
success:function(data){
// successful request; do something with the data
alert('success');
},
error:function(){
// failed request; give feedback to user
alert('error');
}
});
}
});
The problem is that sometimes the cart is submitted before the ajax call is done.
Is there another way to do this?