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

How can I limit product order quantity to one in Dawn Theme?

Solved

How can I limit product order quantity to one in Dawn Theme?

_Tom_
Tourist
8 2 7

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

Accepted Solutions (2)
_Tom_
Tourist
8 2 7

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.

View solution in original post

PaulNewton
Shopify Partner
7450 657 1565

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

 

https://help.shopify.com/en/manual/online-store/themes/theme-structure/templates#:~:text=the%20selec... 

 

If either helped mark the solutions for future merchants, thanks

 

Contact paull.newton+shopifyforum@gmail.com 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


View solution in original post

Replies 6 (6)

PaulNewton
Shopify Partner
7450 657 1565

 

{% 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 paull.newton+shopifyforum@gmail.com 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


_Tom_
Tourist
8 2 7

@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?

_Tom_
Tourist
8 2 7

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.

Pair_of_Squares
Excursionist
16 0 4

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...

PaulNewton
Shopify Partner
7450 657 1565

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

 

https://help.shopify.com/en/manual/online-store/themes/theme-structure/templates#:~:text=the%20selec... 

 

If either helped mark the solutions for future merchants, thanks

 

Contact paull.newton+shopifyforum@gmail.com 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


Jahid-KlinKode
Excursionist
145 1 5

Hi @_Tom_, wondering how to restrict specific products or pages on Shopify? Watch this informative video tutorial: