How to show inventory quantity on the product page on Shopify

We will see in this tutorial how you can display the stock on your shopify product page

It is important for your customer to know if you have any units left in stock for your products and it also makes your product page more attractive.

Remember that in this tutorial we will display the real stock that combines all variants. This means that it is not recommended for dropshipping stores because the notion of out of stock is not the same.

You can see the end result on this demo store :

Password : Speedecom

Let’s get technical ! πŸ™‚

How to install the code

Go to the code editor of your shopify theme and open the “sections” folder.

Find the product-template.liquid file and use the search bar with Ctrl + F (or cmd + R) to find the line that contains “price”. Here is an example for the Debut theme.

If you can’t find this area try putting a random word at different places and refresh your product page to find the right spot.

You will now copy/paste the following code to that spot

.sd-items-count p { color:#ff2200; font-size:15px; padding:7px 0; margin:0; }
.sd-items-count img { float:left; width:20px !important;height:auto !important;margin:0 7px 0 0; padding:0; }
{% 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 %}
<div class="sd-items-count">          
There are <span class="sd-count"><strong>{{ product_qty }}</strong></span> units left in stock.</p>
{% endif %}

If you want to put it on the featured product of your homepage, you will just have to find the file featured-product.liquid file in the sections folder.

Depending on the theme the name of the file may not necessarily be the same but if it is well coded then it will be πŸ˜‰.

This tutorial is also available in video format

Hope you found this tutorial helpful !

You have any ideas for new tutorials ? Any questions about this one ? Leave me a comment πŸ˜‰

Share this article

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on telegram
Share on whatsapp
Share on email

10 Responses

  1. This was EXCELENT and did almost exactly what I was looking for!

    One thing, is it possible to do the same thing for variants? So it shows inventory on a specific variant enventory…

    Shoe Size
    9 (5 in stock)
    10 (2 in stock)
    11(Out Of Stock)
    12 (Out Of Stock)
    13 (1 in stock)

    instead of how it is now that shows 8 In Stock regardless of what variant you click on.

    Here’s one of my products as example…

    1. Thank you for your comment πŸ™‚

      Hmm, unfortunately, from what it know it is not possible on Shopify because of technical limitations, not out of lack of wanting. Shopify groups the stock of all variants together.

  2. I want to hide product variants if variant quantity is less than three. or show out of stock if variant quantity is less than three.

  3. Thank you very much! It was very easy to follow your instructions and I was able to display the total quantities remaining for the total number of variants.

    Is it easy to modifiy the code to only show the quanities for specific items with a specific tag referenced?

  4. OMG! Thank you so much for this great tutorial! It did exactly what I needed quick simple and easy! I was very nervous about modifying adding to my code… This is all extremely new to me, but you made it easy to follow and understand! Thank you thank you thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *