Ajax cart fix
This commit is contained in:
parent
d3377cdfc6
commit
b8636296ff
|
@ -30,7 +30,15 @@ jQuery(function(){
|
|||
jQuery.post( woocommerce_params.ajax_url, data, function(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
|
||||
if (fragments) {
|
||||
|
|
|
@ -69,12 +69,18 @@ function woocommerce_ajax_add_to_cart() {
|
|||
|
||||
$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
|
||||
$data = apply_filters('add_to_cart_fragments', array());
|
||||
else :
|
||||
// Return error
|
||||
$data = array(
|
||||
'error' => woocommerce::$errors[0]
|
||||
);
|
||||
woocommerce::clear_messages();
|
||||
endif;
|
||||
|
||||
// Return html fragments
|
||||
$fragments = apply_filters('add_to_cart_fragments', array());
|
||||
|
||||
echo json_encode( $fragments );
|
||||
echo json_encode( $data );
|
||||
|
||||
die();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue