Advertisement
fahimmurshed

remove product on zero quantity (mini cart)

Aug 8th, 2023
1,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. add_filter( 'woocommerce_add_to_cart_validation', 'astra_remove_product_on_zero_quantity', 10, 3 );
  2. function astra_remove_product_on_zero_quantity( $passed, $product_id, $quantity ) {
  3.     $cart = WC()->cart;
  4.    
  5.     // Loop through cart items
  6.     foreach( $cart->get_cart() as $cart_item_key => $cart_item ) {
  7.         // Check if quantity is zero
  8.         if( $cart_item['quantity'] == 0 ) {
  9.             // Remove item from the cart
  10.             $cart->remove_cart_item( $cart_item_key );
  11.         }
  12.     }
  13.    
  14.     return $passed;
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement