Display total quantity of products including variations

Hey so when i add the feature to show quantity it shows each variation’s quantity so for example it says one instead of 32, is there a way for it show the total quantity available for the product so if there are 32 variations with 1 each i would like it to say 32 instead of 1. Any help would be greatly appreciated.

Hi, If you are using Dawn theme, there is block “Inventory status” to show Inventor indicator by variant and if you are mind to write all stock in variants then write this code in “Custom Liquid” block.

{% assign totalProductsQuantity = 0 %}
{% for variant in product.variants %}
{% assign totalProductsQuantity = totalProductsQuantity | plus: variant.inventory_quantity%}
{% endfor %}
Total Quantity: {{ totalProductsQuantity }}

Hopefully it will help you. If yes then Please hit Like and Mark it as solution!

thank you for the quick response! I am not a experienced in custom coding, the code did work on the product page itself, is there a way to add it to the listing on the home page under the featured collection?

Hi to do that you need edit 2 files liquid.

Hope that is help.

1 Like