Show Stock Level (non specific) on Product Pages

I’ve been at this for several hours now and can’t seem to get the output I want with my limited coding abilities. Can’t find answer in the forums, so thought I’d ask.

I found this code to show stock levels and/or OOS message:


{% 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 %}
          

**{{ product_qty }}** units left in stock.

{% else %}
Out of stock. [Contact us](https://www.ledspace.co.uk/pages/contact-us) for alternatives.

{% endif %}

However, what I’m trying to do is show a different message based on quantity in stock, so, for example,

If <10 show message: “Just {{ product_qty }} units left in stock”

If <100 show message: “Less than 100 units in stock” (not showing specific #)

If >100 show message: “More than 100 units in stock” (not showing specific #)

At the moment, I end up with more than 1 message showing. Best way of doing this?

Thanks

If I apply you request in the code you shared then it should be


{% 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 < 10  %}
          

Just {{ product_qty }} units left in stock

{% elsif product_qty < 100 %}
          

Less than 100 units in stock" (not showing specific #)

{% elsif product_qty > 100 %}
          

More than 100 units in stock" (not showing specific #

{% endif %}

Thanks

1 Like

Perfect, thank you so much!