Number input "max" not showing on Product form but works in cart

Number input "max" not showing on Product form but works in cart

JoeCat
Shopify Partner
42 2 23

I am trying to put a max qty limit on the qty input of the product page.

 

On my product-form file I'm including 

{% if item.product.tags contains 'max5' %}
    <input type="number" min="1" max="5" size="2" class="quantity" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" data-cart-quantity-input="cart-template"  />
  {% elsif item.product.tags contains 'max4' %} ...........

on the product page - the  max="5" disappears.   I can change any other number such as size, min or value and it updates just fine.   but the results on the Product page look like this (notice Max is missing)

<input type="number" min="1" size="2" class="quantity" name="quantity" id="quantity" value="1">

 

I am using nearly identical code in the cart - and it works fine there

{% if item.product.tags contains 'max5' %}
    <input type="number" min="1" max="5" size="2" class="quantity" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" data-cart-quantity-input="cart-template"  />
  {% elsif item.product.tags contains 'max4' %}....

 

Dawn theme. 

 

 

Happy to share knowledge of simple code changes. Click the link in my profile if you need help implementing.
Reply 1 (1)

made4Uo
Shopify Partner
3873 718 1217

Hi @JoeCat 

 

I see your max number changes. The cleaner way to do this is use product metafield to assign the max for you

 

This is the metafield settings I used

made4Uo_2-1664567801097.png

 

1. From your Admin Page, click Online Store > Themes >Actions > Edit code
2. In the Section folder, open the main-product.liquid
3. Find the quantity__input, then below the min="1", paste the code below

 

{% if product.metafields.custom.max_number != blank  %}max="{{ product.metafields.custom.max_number }}"{% endif %}

 

 

See image for code placement

made4Uo_1-1664567683624.png

 

4. We have to do the same in the cart page.

5. In the Section folder, open the main-cart-items.liquid
6. Find the quantity__input, then below the min="1", paste the code below

 

{% if product.metafields.custom.max_number != blank  %}max="{{ product.metafields.custom.max_number }}"{% endif %}

 

 

See image below for placement

made4Uo_4-1664568095265.png

 

 

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free