Suppy - Show remaining inventory on home page

Tourist
7 0 1

Hi all -

 

I am using the Supply theme and currently have the below set up to show the remaining stock of all variants of a product on the product page. Due to the nature of my business, I would also like to show the total quantity left in stock right on my home page - I use the "featured collection" section on my home page that displays a collection of products. It currently shows a product image, title and price. How do I also display the remaining inventory here? 

 

This is what I use in the product-template.liquid:

{% assign total=0 %}
{%for variant in product.variants %}
{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
{% assign total = i %}
{%endfor%}
<b>Total Qty Avalaible : </b>{{ total }}

 

If anyone can give me something to copy and paste it would be great appreciated as I am not that savvy with the coding. 

 

Thank you!

0 Likes
Shopify Partner
462 80 94

@nuckbuc04 

 

Click on Action > Edit Code.

Here find/search product-grid-item.liquid file

Scroll at line 96 or 97, right after closing </div> past the following code.

      <p>
      	{% assign total=0 %}
      	{%for variant in product.variants %}
      	{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
      	{% assign total = i %}
      	{%endfor%}
      	<b>Total Qty Avalaible : </b>{{ total }}
      </p>

If you want to show qty only on homepage, then instead of above add the below one, where we are also checking the template

 

{% if template contains 'index' %}
      <p>
      	{% assign total=0 %}
      	{%for variant in product.variants %}
      	{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
      	{% assign total = i %}
      	{%endfor%}
      	<b>Total Qty Avalaible : </b>{{ total }}
      </p>
{% endif %}

Anyway, after the edits, the file should looks similar to this screenshot:

 

T2Mz68r

Author: Hovhannes Sargsyan (aka sarhov).
An individual web developer focused on Shopify development.
Need more help? Feel free to send me a direct message or drop an email shopify@sarhov.com

Website: https://sarhov.com  
Email: shopify@sarhov.com
Skype: @sarhov
Messenger: @sarhov
Telegram: @sarhov
1 Like
Tourist
7 0 1

That worked!  Thank you SOOO much!

0 Likes
Shopify Partner
462 80 94

@nuckbuc04 

 

You're welcome...

Please accept my answer as a solution if it helped.

Thank you... ))

Author: Hovhannes Sargsyan (aka sarhov).
An individual web developer focused on Shopify development.
Need more help? Feel free to send me a direct message or drop an email shopify@sarhov.com

Website: https://sarhov.com  
Email: shopify@sarhov.com
Skype: @sarhov
Messenger: @sarhov
Telegram: @sarhov
0 Likes
Excursionist
11 0 1

Hey @nuckbuc04 where did you add this code in product-template.liquid?

0 Likes
Tourist
7 0 1

@steveisaacs I added this to the product-grid-item.liquid file only at line 96 or 97, right after closing </div> 

 

   <p>      	{% assign total=0 %}
      	{%for variant in product.variants %}
      	{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
      	{% assign total = i %}
      	{%endfor%}
      	<b>Total Qty Avalaible : </b>{{ total }}
      </p>

 

0 Likes
Excursionist
11 0 1

Sorry, I meant where did you put the code from your original post so the inventory count appears on the product page itself?

 

Like, where you put the code on the product-template.liquid page?

 

Also while we're at it, when I put that code in for the quantity count on the product-grid-item page, if I haven't specified an inventory number, some products display as quantity "0". Some of my products are POD shirts, and have no limit or quantity number. Is there a way to control the inventory counts so they don't show the "0" for products like this?

 

Thanks!

0 Likes
Tourist
7 0 1
You should be able to put it anywhere - just test and see if it's a spot
that you like and if not move it around.
1 Like
Highlighted
Excursionist
11 0 1

Worked great!

 

Also did you have any info about my question above - about keeping certain products not showing "0 available" if I DON'T specify a limited quantity?

 

Screen Shot 2019-09-08 at 12.22.01 PM.png

0 Likes