Display the first price that not zero from an product's variants array

Solved
Ultipower
New Member
5 0 0

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.

Accepted Solution (1)

Accepted Solutions
LitExtension
Shopify Partner
1934 314 391

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!

LitExtension - #1 Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!

View solution in original post

Replies 2 (2)
LitExtension
Shopify Partner
1934 314 391

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!

LitExtension - #1 Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!

View solution in original post

Ultipower
New Member
5 0 0