AgentReadyAI visibility appCaffeine & CommerceShopify agency
Caffeine and Commerce
Caffeine and Commerce
By Dylan HuntJune 18th, 2024shopifyliquid

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>

Make your store agent-ready

Get found and recommended by AI shopping assistants.

AgentReady adds Schema.org structured data, an llms.txt directory, and an AI-readability audit to your Shopify store, so ChatGPT, Perplexity, and Google can understand and recommend your products. Free for stores under 500 products.

Comments

Every comment here comes from a verified email. Write yours, confirm from your inbox, and it's live.

Loading comments…

Leave a comment

ShareXLinkedInFacebook

Written by Dylan Hunt, Founder, Caffeine and Commerce. We build Shopify stores that rank and that AI agents can read. Have a project? Get in touch.