Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello everyone, I know many asked this question before but i'm still struggeling with that. I want to limit order quabtity to 1 for a specific product. I know I have to edit my code at this section:
<div class="product-form__input product-form__quantity" {{ block.shopify_attributes }}>
<label class="form__label" for="Quantity-{{ section.id }}">
{{ 'products.product.quantity.label' | t }}
</label>
<quantity-input class="quantity">
<button class="quantity__button no-js-hidden" name="minus" type="button">
<span class="visually-hidden">{{ 'products.product.quantity.decrease' | t: product: product.title | escape }}</span>
{% render 'icon-minus' %}
</button>
<input class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
min="1"
value="1"
form="{{ product_form_id }}"
>
<button class="quantity__button no-js-hidden" name="plus" type="button">
<span class="visually-hidden">{{ 'products.product.quantity.increase' | t: product: product.title | escape }}</span>
{% render 'icon-plus' %}
</button>
</quantity-input>
</div>
I know I have to put an if/else snippet here, but I don't really know how. I tried a few things but everytime an Error pops up like: Liquid syntax error: Unknown tag 'when'
I'm using the Dawn Theme
Solved! Go to the solution
This is an accepted solution.
{% assign productTags = product.tags %}
{% if productTags contains "noquantity" %}
<input class="quantity__input"
type="hidden"
name="quantity"
id="Quantity-{{ section.id }}"
min="1"
value="1"
max="1"
form="{{ product_form_id }}"
>{% else %}
<quantity-input class="quantity">
....
{% endif %}
@PaulNewton ok that works for me thank you for showing me the right direction.
This is an accepted solution.
@_Tom_ wrote:@PaulNewton sorry that didn't work for me, when I just put a max attribute to the original code, that works but I can't point to a specific Item. When i create a new template how can I use this then?
Alternate templates are applied per resources in that resources admin , outside of the theme editor.
For products and pages this is a selector on the right sidebar when the live theme has an alternate template for that resource type
If either helped mark the solutions for future merchants, thanks
Contact [email protected] for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
{% assign limited_product_handle = 'product-handle-string' %}
{% if product.handle == limited_product_handle %}
<input class="quantity__input"
type="hidden"
name="quantity"
id="Quantity-{{ section.id }}"
min="1"
value="1"
max="1"
form="{{ product_form_id }}"
>
{% else %}
<quantity-input class="quantity">
....
{% endif %}
The alternative is to use alternate templates for those specific product where the custom component <quantity-input class="quantity"> is completely replaced with a basic hidden input.
Or course the deeper problem here is these triput button components are never made to obey the max attributes values on the input itself so the minus/plus will ignore a max="1" declaration.
Contact [email protected] for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
@PaulNewton sorry that didn't work for me, when I just put a max attribute to the original code, that works but I can't point to a specific Item. When i create a new template how can I use this then?
This is an accepted solution.
{% assign productTags = product.tags %}
{% if productTags contains "noquantity" %}
<input class="quantity__input"
type="hidden"
name="quantity"
id="Quantity-{{ section.id }}"
min="1"
value="1"
max="1"
form="{{ product_form_id }}"
>{% else %}
<quantity-input class="quantity">
....
{% endif %}
@PaulNewton ok that works for me thank you for showing me the right direction.
Did this solution work for you? I have the same situation, I also need to limit a product quantity per order. I need no more than 5 items per order of one product due to specifics of shipping. I do not code at all so I have no idea where to insert this code...
This is an accepted solution.
@_Tom_ wrote:@PaulNewton sorry that didn't work for me, when I just put a max attribute to the original code, that works but I can't point to a specific Item. When i create a new template how can I use this then?
Alternate templates are applied per resources in that resources admin , outside of the theme editor.
For products and pages this is a selector on the right sidebar when the live theme has an alternate template for that resource type
If either helped mark the solutions for future merchants, thanks
Contact [email protected] for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Hi @_Tom_, wondering how to restrict specific products or pages on Shopify? Watch this informative video tutorial:
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024