How to show low inventory for all variants on product page?

How to show low inventory for all variants on product page?

Andia
Tourist
61 0 2

im trying to use this code:

 

{% if product.variants.first.inventory_quantity < 5 and product.variants.first.inventory_quantity > 0 %} <p style="color: #000000; text-align:center">ONLY {{ product.variants.first.inventory_quantity }} LEFT</p> {% elsif product.variants.first.inventory_quantity < 1 %} <p style="color: #000000; text-align:center">SOLD OUT</p> {% endif %}

 

but it only seems to work on the first variant and doesnt work when i change variants (ie XS, S, M etc)

 

Can anyone help with adjusting the code??

Replies 4 (4)

AnneLuo
Shopify Partner
1252 222 257

Hello, @Andia 

What theme are you using? Can you share your store url?

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me   

Buy Me A Coffee

Andia
Tourist
61 0 2

theycallmemakka
Shopify Partner
1771 432 455

Hi @Andia ,

 

You will have to modify JS to make this work. Currently you have added only the DOM elements. To make it dynamic, we will have to add custom JS[Most probably in global.js]. 

Support Me: Buy me a Coffee


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

Andia
Tourist
61 0 2

how do i do this?!