How to display Product Stock Count on product cards

Solved

How to display Product Stock Count on product cards

IntechCarl
Shopify Partner
194 1 20

Hi everyone,

Is there a way to display the stock count/information in product cards in my collections page/ featured collection? See photo for reference:

Store Preview Link: https://0tom0bitnjf5bzka-13830324282.shopifypreview.com

 

IntechCarl_0-1740988117689.png
This is the store that I want to copy:

IntechCarl_0-1740990133439.png

 

 

Accepted Solution (1)
SUM0513
Shopify Partner
11 1 5

This is an accepted solution.

The snippet fetches the 'product' object with an alias 'card_product' (You can see this on the top of the snippet code) , so we'll need to use replace the code as:

 

{{ card_product.first_available_variant.inventory_quantity }}

 

 

According to the the reference, it's best to put the code above the "{% render 'price'..." line, which displays the number right above the price in frontend.

SUM0513_0-1741060922941.png

 

However, if you want to put it above the reviews, you may place the code above the " {%- if show_rating and card_product.metafields.reviews.rating.value != blank -%}" line.

SUM0513_1-1741061068775.png

 

Eitherway, you'll have to place it in a way that doesn't obstruct the liquid logic and the frontend design.

 

 

View solution in original post

Replies 15 (15)

SUM0513
Shopify Partner
11 1 5

Hey there,

You could add this code inside your product-card snippet:

{{ product.first_available_variant.inventory_quantity }}

This code essentially renders the inventory quantity for the first product variant that is currently available in stock.

 

IntechCarl
Shopify Partner
194 1 20

@SUM0513 Hi!, Thank you for your response, but I don't have a product-card snippet. See photo for reference:

IntechCarl_0-1740993038487.png

 

SUM0513
Shopify Partner
11 1 5

I was actually referring to a general 'product card' snippet that gets rendered in the collection pages. Since you might be using 'Dawn' theme, there must be a 'card-product.liquid' snippet. You'll have to make changes inside this file.

 

 

IntechCarl
Shopify Partner
194 1 20

@SUM0513 I found a card-product snippet, which line should I put the code?

SUM0513
Shopify Partner
11 1 5

This is an accepted solution.

The snippet fetches the 'product' object with an alias 'card_product' (You can see this on the top of the snippet code) , so we'll need to use replace the code as:

 

{{ card_product.first_available_variant.inventory_quantity }}

 

 

According to the the reference, it's best to put the code above the "{% render 'price'..." line, which displays the number right above the price in frontend.

SUM0513_0-1741060922941.png

 

However, if you want to put it above the reviews, you may place the code above the " {%- if show_rating and card_product.metafields.reviews.rating.value != blank -%}" line.

SUM0513_1-1741061068775.png

 

Eitherway, you'll have to place it in a way that doesn't obstruct the liquid logic and the frontend design.

 

 

IntechCarl
Shopify Partner
194 1 20

Hi @SUM0513 I have added the code, and it successfully display the product count but, the problem is how do I style it? It's just a plain number. I want to have it look like " In stock (54)" with green font and if "Out of Stock" Red font. Also it overlaps with my product ratings See photo for reference: 

IntechCarl_2-1741063543475.png

 

IntechCarl
Shopify Partner
194 1 20

hi @SUM0513, nevermind the styles I already fix it. The problem now is it is only visible in featured collection in my homepage, I want it be displayed in my product collection page. See photo for reference: 

 

IntechCarl_4-1741064065546.png

 

SUM0513
Shopify Partner
11 1 5

To make it look like the reference site, you could try out this code:

 

{% if card_product.available %}
  <span class='stock--available'>
    In stock ({{ card_product.first_available_variant.inventory_quantity }})
  </span>
{% else %}
  <span class='stock--unavailable'>
    Out of stock
  </span>
{% endif %}

 

The availability of the product decides which content to show. Style the individual span classes as you'd want. 

IntechCarl
Shopify Partner
194 1 20

@SUM0513 I already fix the styling, I only need to display it on product collection page, It is already showing in featured collection in my homepage, I want it to be visible Inside the Collection See photo for reference:

IntechCarl_0-1741065449954.png

 

SUM0513
Shopify Partner
11 1 5

Hmm, this is weird. The previous adjustments should've made it work, since be it featured collection or collection pages, they all render the same card-product snippet. Just for measure, could you double check the products and their inventory quantities?

IntechCarl
Shopify Partner
194 1 20

@SUM0513  I have checked the products and their inventory, I think they are all fine. Maybe the collection pages have different file?

SUM0513
Shopify Partner
11 1 5

Could you send me a screenshot of where you've placed the above code? In dawn, the collection pages seem to render the same snippet.

 

IntechCarl
Shopify Partner
194 1 20

@SUM0513 this is where I inserted it:

IntechCarl_0-1741066472713.png

 

SUM0513
Shopify Partner
11 1 5

Just to make sure, the quick add setting is off right? Also I want you to debug this. Could you write 'test' under the '{% endif %}' and check the frontend, does the 'test' appear on the website after a hard reload? (ctrl + shift + R)

IntechCarl
Shopify Partner
194 1 20

Yes, the quick add is off. I added the test below the code and it is only visible on featured collection in home page not in collection pages

IntechCarl_0-1741067194532.png

IntechCarl_1-1741067208923.png