Ajax cart fix

This commit is contained in:
Mike Jolley 2011-08-30 12:43:16 +01:00
parent d3377cdfc6
commit b8636296ff
2 changed files with 20 additions and 6 deletions

View File

@ -30,7 +30,15 @@ jQuery(function(){
jQuery.post( woocommerce_params.ajax_url, data, function(response) { jQuery.post( woocommerce_params.ajax_url, data, function(response) {
// Get response // Get response
fragments = jQuery.parseJSON( response ); data = jQuery.parseJSON( response );
if (data.error) {
alert(data.error);
jQuery(thisbutton).removeClass('loading');
return;
}
fragments = data;
// Block fragments class // Block fragments class
if (fragments) { if (fragments) {

View File

@ -69,12 +69,18 @@ function woocommerce_ajax_add_to_cart() {
$product_id = (int) $_POST['product_id']; $product_id = (int) $_POST['product_id'];
woocommerce_cart::add_to_cart($product_id, 1); if (woocommerce_cart::add_to_cart($product_id, 1)) :
// Return html fragments // Return html fragments
$fragments = apply_filters('add_to_cart_fragments', array()); $data = apply_filters('add_to_cart_fragments', array());
else :
// Return error
$data = array(
'error' => woocommerce::$errors[0]
);
woocommerce::clear_messages();
endif;
echo json_encode( $fragments ); echo json_encode( $data );
die(); die();
} }