Show variant stock quantity - modify code

Hi team,

I’m using this code I found online:


{% assign product_qty = 0 %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign product_qty = product_qty | plus: variant.inventory_quantity %}
{% endif %}
{% endfor %}
{% if product_qty > 0 %}
          

We have **{{ product_qty }}** in stock. If you need more please let us know.

{% endif %}

which works perfectly, except for products that have multiple variants, where it just puts the total amount across all variants.

Can someone please help me modify this code to show for variants?

TIA!

Bump to see if anyone has an idea on how to make this work for me :slightly_smiling_face: