How to Display Remaining Product Quantities to Customers on Shopify

In Shopify Liquid, you can show your customer the stock level of a specific product variant.

Before you do this, ensure that your theme doesn't already have a method for doing this, such as: 

To do this, you'll need to access the inventory_quantity attribute of a variant. This attribute gives you the quantity of that specific variant in stock. It's important to note that this does not sum the totals of all variants, but rather shows the quantity for each individual variant.

Here's a basic example of how you might implement this in your Shopify Liquid template:

{% for variant in product.variants %}
  <div class="product-variant">
    <span class="variant-title">{{ variant.title }}</span>
    <span class="variant-inventory">In stock: {{ variant.inventory_quantity }}</span>
{% endfor %}

In this example:

  • The {% for variant in product.variants %} loop iterates over each variant of the product.
  • {{ variant.title }} outputs the title of each variant.
  • {{ variant.inventory_quantity }} displays the stock level for each variant.

This code will list all the variants of a product and show the available stock for each variant separately. Just make sure you insert this code snippet into the appropriate Liquid file where you want this information to be displayed (like a product detail page).

Also, be aware that displaying inventory quantities can have implications for your store's operation, such as potentially revealing low stock levels to competitors. So, use this feature considering your overall business strategy.

Back to blog