How to show inventory on the collection page

Hi Guys,

I just want to show the stock left on my collection page.

Just under the price I would like to show the inventory left if it’s possible. I figure out how to show the inventory on my product page with a couple of tutorial on the web. I’m a beginner with the coding, so if you could explain me where I need to put the code, I would really appreciated!

P.S : I’ve used the narrative theme

Thanks in advance!

You can try to add the following code to Narrative product-card.liquid file

{% if variant.available %}
            {{ variant.inventory_quantity }} in stock

          {% endif %}

After line 52, after the {% endif %}

Full code here for reference


          {%- assign variant = product.selected_or_first_available_variant %}
          {% if product.compare_at_price > product.price %}
            {% comment %}
              Product is on sale
            {% endcomment %}
            {% if product.price_varies %}
              {% assign sale_price = product.price | money_without_trailing_zeros %}
               {{ 'products.product.price' | t }} 
              {{ 'products.product.on_sale_from_html' | t: price: sale_price }}
            {% else %}
              {{ 'products.product.sale_price' | t }}
              {{ product.price | money_without_trailing_zeros }}

              {{ 'products.product.regular_price' | t }}
              
                {{ product.compare_at_price | money_without_trailing_zeros }}
              
              {%- if variant.available and variant.unit_price_measurement -%}
                {% include 'product-unit-price', variant: variant %}
              {% endif %}
            {% endif %}

          {% else %}
            {% comment %}
              Not on sale, but could still have varying prices
            {% endcomment %}
            {% if product.price_varies %}
              {% assign price = product.price | money_without_trailing_zeros %}
              {{ 'products.product.from_text_html' | t: price: price }}
            {% else %}
              {{ product.price | money_without_trailing_zeros }}
              {%- if variant.available and variant.unit_price_measurement -%}
                {% include 'product-unit-price', variant: variant %}
              {% endif %}
            {% endif %}
          {% endif %}

          {% if variant.available %}
            
{{ variant.inventory_quantity }} in stock

          {% endif %}
          
        

1 Like

@drakedev

Wow thanks a lot, it’s work!!!