Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_add_to_cart_validation', 'astra_remove_product_on_zero_quantity', 10, 3 );
- function astra_remove_product_on_zero_quantity( $passed, $product_id, $quantity ) {
- $cart = WC()->cart;
- // Loop through cart items
- foreach( $cart->get_cart() as $cart_item_key => $cart_item ) {
- // Check if quantity is zero
- if( $cart_item['quantity'] == 0 ) {
- // Remove item from the cart
- $cart->remove_cart_item( $cart_item_key );
- }
- }
- return $passed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement