I have a Shopify site with multiple categories. Some products do not have a price (Shopify interests this as $0). All collections are displayed on the front page. I want to loop through all products in each collection and output the minimum price (excluding $0 values).
The current array I’m using is:
{% assign startingFrom = collection.products | sort: 'price' %}
{{ startingFrom[0].price_min | money_without_currency }}
Unfortunately, this captures and outputs $0 values.
What is the best way to loop through values that are higher than $0 and output the lowest price?
I have tried to exclucde zero values:
{% assign startingFrom = collection.products | sort: 'price' %}
{% if 'price' != 0.00 %}
{{ startingFrom[0].price_min | money_without_currency }}
{% endif %}
This outputs $0.00.
2
Answers
it is not tested but it should work.
You can’t rely on that way unless you have fewer than the pagesize limit of products in your collection.
See the discussion and solution under Shopify: Getting highest price item from collection