All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Is there a way to limit the product quantity a customer can add to their cart to be no more than what you've set as available in the inventory?
Looked at previous main-product.liquid suggestions which are a couple of years old and don't work in the new code.
Really frustrating that customers can add more of a product than is available and don't find out until they click add to cart.
Hi, @glassmaker
Yes, there is a way to limit the product quantity a customer can add to their cart.
You can do this by adding this line:
max="{{current_variant.inventory_quantity}}"
to your quantity input field in your cart or product template.
This will limit the maximum quantity a customer can add to their cart to the available inventory for that product.
Let me know how that works for you.
Thank you for your help! Sadly it isn't working putting it in the product template code, even though it looks like it should definitely be working
What you want is to add the attributes "max" and "data_max" to the input in main-product.liquid like this:
```
<input
class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
data-cart-quantity="{{ cart_qty }}"
data-min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
...
data-max="{{product.selected_or_first_available_variant.inventory_quantity}}"
max="{{product.selected_or_first_available_variant.inventory_quantity}}"
...
```
did you ever figure out how to make this work ?