Back to Blog

2024-06-18

shopifyliquid

Show Remaining Inventory of All Variants Combined for Product

Show Remaining Inventory of All Variants Combined for Product

Here is the code to show the inventory quantity of each product on a collection or product page, instead of just showing the first available variants. Note, this guide will only show if inventory is below 4.

<div id="variant-inventory">
  {% assign total = 0 %}
  {%for variant in product.variants %}
    {% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
    {% assign total = i %}
  {%endfor%}
  {% unless total == '0' %}
    Only {{ total }} left
  {% endunless %}
</div>