try to fix duplicated cart items
This commit is contained in:
@ -209,3 +209,21 @@ function bbloomer_order_completed_email_add_cc_bcc($headers, $email_id, $order)
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force empty cart before adding new items
|
||||
* Prevents users from having multiple products in cart at once
|
||||
*/
|
||||
function force_single_item_cart($passed, $product_id, $quantity) {
|
||||
// If cart is not empty and we're adding a new product
|
||||
if (!WC()->cart->is_empty()) {
|
||||
// Show notice to the user
|
||||
// wc_add_notice(__('Your cart has been emptied to add this new item. Only one product can be purchased at a time.', 'somos-infinitos-theme'), 'notice');
|
||||
|
||||
// Empty the cart
|
||||
WC()->cart->empty_cart();
|
||||
}
|
||||
|
||||
return $passed;
|
||||
}
|
||||
add_filter('woocommerce_add_to_cart_validation', 'force_single_item_cart', 10, 3);
|
||||
|
Reference in New Issue
Block a user