getting the smaller number of an array

Highlighted
Shopify Expert
7 1 0

Hi,

I need to iterate through the variants of a product, and get the lowest price. I got to this point:

{% for variant in product.variants %}
  {% assign temp = variant.price %}
  {% unless variant_option2 contains temp %}
  {% assign variant_option2 = variant_option2 | append:temp %}
  {% endunless %}
{% endfor %}
{{ variant_option2 | sort | first}}

But, the way how I added the filters doesn't work.

I tried to sort the array and get the first element.

How do I get the smalles number of an array?

 

Thanks

Zin

0 Likes
Shopify Partner
177 16 20

Hi, Zin:
You can get the lower price of a product using:

{{ product.price_min }}

Also you can sort the array by price:

{{ variant_option2 | sort: 'price' | first}}
Let's make the best store!
Contact us at: thepremierstores@gmail.com
0 Likes