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

Andia
Tourist
47 0 1

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
422 86 79

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
47 0 1

theycallmemakka
Shopify Partner
1477 336 360

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

Buy me a Coffee


Enjoy Shopify for $1. Sign up now


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

Andia
Tourist
47 0 1

how do i do this?!