Showing Stock Levels On Collection Page

Highlighted
New Member
3 0 0

Hey guys. I've found a few posts of people talking about how to do this, but it's elluding me. I'm super new to this, but I have a background in C#, so I understand the basics of coding. I've been trying to put the number of stock I have for each item in a collection on the collection page, so customers don't have to click an item to be able to see if they can buy it. I've been trying to edit the collection.liquid to show it, but I don't seem to be getting anywhere. If someone could help I would really appreciate it.

0 Likes
Highlighted
Astronaut
1890 1 443

collection.liquid likely refers to a snippet, for example, product-loop.liquid.  You will probably want to edit this file.

Here's something to get you started.  Note that products do not have an associated inventory quantity.  Instead the variants of the product have an associated inventory quantity.  You might want to sum up these quantities.

{% assign product_quantity = 0 %}
{% for variant in product.variants %}
  {% assign product_quantity = product_quantity | plus: variant.inventory_quantity %}
{% endfor %}
<div>Number of available units for this product (i.e. the sum of the quantities of each of this product's variants): {{ product_quantity }}</div>

If you're only interested in knowing whether or not the product has any (i.e. product quantity >= 1), you can use:

{% if product.available %}
<div>Product is available.</div>
{% else %}
<div>Product is not available.</div>
{% endif %}

I hope this helps.

0 Likes
Highlighted
New Member
3 0 0

I don't have a product-loop.liquid. I have a product.liquid that I've edited so it shows the quantity inside of the product page, but I need to see it when I'm scrolling through the collection. I'm sorry, I just don't get it. It's very frustrating trying to figure this all out, so I appreciate your help very much.

Is there something that explains the snippets and templates? I'd love to learn more.

 

0 Likes
Highlighted
New Member
3 0 0

Oh my god! I put it into product-list.item.liquid and it worked! This is amazing!

Is there a good resource to learn this better? Is there anyone that would be willing to tutor me for afew hours (paid of course) to help me learn it a little better?

0 Likes