Woocommerce – Items with a quantity of 0 are added to the cart?

I have item quantities on the shop page next to each item. The user can enter their quantity and click the add to cart button, which will add the item to the cart using ajax. By default I have the item quantity set to 0; however if the user clicks the add to cart button when the quantity is 0, the item will be added to the cart with a quantity of 1.

What I want to happen is if the item quantity is 0 then a message will appear telling the user to enter their quantity and the item will not be added to the cart.

Read More

Is this possible? Any help would be appreciated.

Related posts

1 comment

  1. This should work, add This to your custom JS code.

    jQuery( document ).ready(function() {
      jQuery(".woocommerce div.product form.cart .button").click(function(){
        if(jQuery('input[name="quantity"]').val() == 0 || 'input[name="quantity"]').val() == ""){
           alert("Quantity should be at least 1. The item will not be added to cart.");
           return false;
        }
      });
    });
    

Comments are closed.