How to limit the quanitity of stock available on product.

How to limit the quanitity of stock available on product.

HVTS
New Member
5 0 0

Trying to make it so that if stock exceeds 8 in stock it shows 8+ in the stock available on the product, is there an easy way to do this?

Replies 2 (2)

PaulNewton
Shopify Partner
7450 656 1562

Hi @HVTS 👋 if the product has a single variant just check the first ones inventory_quantity amount in some liquid logic.

To show it in some themes use a custom-liquid block on the product templates main section for the product information.

https://shopify.dev/docs/api/liquid/objects/variant#variant-inventory_quantity 

 

If the product has multiple variants with differing inventory that can be an advanced theme customization to update the theme when customers select different variants.

 

If you need this customization then contact me for services
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.

 

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


PaulMartin
Shopify Partner
597 59 144

If the stock already shows up in the product page, then changing how it will look if stock exceeds 8 will be easy. You just need to add a liquid conditional.
Currently, here is how your code will look:

Stock levels: {{ variant.inventory_quantity }}

You'll need to change it into:

{% assign current_stock = variant.inventory_quantity %}
Stock levels: 
{% if current_stock >= 8 %}
 8+
{% else %}
 {{ current_stock }}
{% endif %}
contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ