Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: Limit Adding quantity based on available stock

Limit Adding quantity based on available stock

Eugene_RF
Tourist
11 0 0

<div class="chart-group {% if product.available %}{% else %}sold_out{% endif %}">
{% if product.available %}
<label for="quantity" {% if settings.enable_multilang %}data-translate="cart.label.quantity"{%endif%}>
{{ 'cart.label.quantity' | t }}
</label>
<div class="qty-group">
<button class="des button" type="button">
</button>
<input type="text" class="number" id="quantity" name="quantity" value="1">
<button class="inc button" type="button">
</button>
</div>

 

If been trying to alter this so that consumers cannot add more stock to there cart than whats available, please let me know if there is anything i can implement i've tried multiple scenarios across the forum.

 

for example  data-max="{{product.selected_or_first_available_variant.inventory_quantity}}"
max="{{product.selected_or_first_available_variant.inventory_quantity}}"

but i don't know exactly where to place these lines.

Replies 4 (4)

Robert_Kanaan
Shopify Partner
80 10 22

Hi @Eugene_RF,

 

You're on the right track. Be sure to include the max and data-max attributes on the input element.

 

You might also want to consider using JavaScript to improve the user experience by preventing values beyond the available stock from being entered and providing real-time validation.

Robert Kanaan | Web Developer @ GoVedia
Building apps & custom solutions
robert@govedia.com
https://govedia.com

beauxbreaux
Shopify Partner
263 21 45

<div class="chart-group {% if product.available %}{% else %}sold_out{% endif %}">
{% if product.available %}
<label for="quantity"
{% if settings.enable_multilang %}
data-translate="cart.label.quantity"
{% endif %}>
{{ 'cart.label.quantity' | t }}
</label>
<div class="qty-group">
<button class="des button" type="button"></button>
<input type="text"
class="number"
id="quantity"
name="quantity"
value="1"
{% if product.selected_or_first_available_variant.inventory_management == 'shopify' %}
max="{{ product.selected_or_first_available_variant.inventory_quantity }}"
data-max="{{ product.selected_or_first_available_variant.inventory_quantity }}"
{% endif %}>
<button class="inc button" type="button"></button>
</div>
{% endif %}
</div>

Beaux Barker
Developer
Hire me on Fiverr
Eugene_RF
Tourist
11 0 0

I implemented this and it does not seem to be limiting my quantity selector

dabosh
New Member
5 0 0

In which file to put it? 
I need a solution, so that no matter where + selector for item is clicked, it validates against stock.