Solved

Can you know the count of your current sold out products

DanielJ2
Tourist
10 0 1

Hello! I urgently need the count of the products in my store that says sold out on them. Any help would be greatly appreciated. Thanks!

Accepted Solutions (3)

Alan15
Shopify Partner
145 27 66

This is an accepted solution.

If you just need to display the count on the screen, you can try adding this bit of liquid code to your page:

{% assign count = 0 %}
{% for product in collections.all.products %}
    {% if product.available == false %} 
  		{% assign count = count | plus: 1 %}
    {% endif %}
{% endfor %}
{{ count }}
 
Need more help? Contact me here

View solution in original post

Alan15
Shopify Partner
145 27 66

This is an accepted solution.

It depends where you want the message to appear.

If you are using the Debut theme, for example, and you want the number to show in the header of your site, then add the code in the header.liquid file in the Sections folder; if it's on the product page, then it would go in the product-template.liquid. You will need to experiment with the exact positioning and appearance.

Need more help? Contact me here

View solution in original post

Alan15
Shopify Partner
145 27 66

This is an accepted solution.

Hi,

That that doesn't happen for me; I don't know why it would be counting the Product variants. Is there anything unusual in the setup of your variants?

This is what the documentation says about the the product.available attribute used in the code:

product.available
Returns true if a product is available for purchase. Returns false if all of the products variants' inventory_quantity values are zero or less, and their inventory_policy is not set to "Allow users to purchase this item, even if it is no longer in stock."

Maybe someone else has some ideas, I could be missing something obvious.

 

 

Need more help? Contact me here

View solution in original post

Replies 5 (5)

Alan15
Shopify Partner
145 27 66

This is an accepted solution.

If you just need to display the count on the screen, you can try adding this bit of liquid code to your page:

{% assign count = 0 %}
{% for product in collections.all.products %}
    {% if product.available == false %} 
  		{% assign count = count | plus: 1 %}
    {% endif %}
{% endfor %}
{{ count }}
 
Need more help? Contact me here
DanielJ2
Tourist
10 0 1

Hello. I cant seem to figure out where exactly to add this code.

Alan15
Shopify Partner
145 27 66

This is an accepted solution.

It depends where you want the message to appear.

If you are using the Debut theme, for example, and you want the number to show in the header of your site, then add the code in the header.liquid file in the Sections folder; if it's on the product page, then it would go in the product-template.liquid. You will need to experiment with the exact positioning and appearance.

Need more help? Contact me here
DanielJ2
Tourist
10 0 1

Hey man this works perfectly but the number includes the variants also for example I have 5(19 variants altogether) products that says sold out on them but the code calculates 19. Is it possible to show products only without the variants in them. Thanks a lot!

Alan15
Shopify Partner
145 27 66

This is an accepted solution.

Hi,

That that doesn't happen for me; I don't know why it would be counting the Product variants. Is there anything unusual in the setup of your variants?

This is what the documentation says about the the product.available attribute used in the code:

product.available
Returns true if a product is available for purchase. Returns false if all of the products variants' inventory_quantity values are zero or less, and their inventory_policy is not set to "Allow users to purchase this item, even if it is no longer in stock."

Maybe someone else has some ideas, I could be missing something obvious.

 

 

Need more help? Contact me here