Liquid, JavaScript, themes, sales channels
Hi,
I was wondering if there is a way we can display the first not zero price from the product's variant's array?
Let's assume a product has 5 different variants and their price is like below:
{ A: $0.00, B: $0.00, C:$12.00, D:$13.00, E:$15.00}, I want to display C's price on the frontend, is there a way I can do it with liquid?
Thanks in advance for any helps.
Solved! Go to the solution
This is an accepted solution.
Hi @Ultipower,
Please add code:
{% assign price = product.selected_or_first_available_variant.price %}
{% if price == 0 %}
{% for variant in product.variants %}
{% if price != variant.price %}
{% assign price = variant.price %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
<span class="price">{{ price | money }}</span>
Hope it helps!
This is an accepted solution.
Hi @Ultipower,
Please add code:
{% assign price = product.selected_or_first_available_variant.price %}
{% if price == 0 %}
{% for variant in product.variants %}
{% if price != variant.price %}
{% assign price = variant.price %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
<span class="price">{{ price | money }}</span>
Hope it helps!
It works well thank you.
User | RANK |
---|---|
21 | |
21 | |
8 | |
8 | |
7 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023