Price range for AVAILABLE variants

Shopify Partner
7 0 0

Hi,

 

I would like to show the price range for the available variants for a product:

 

So in this example:-

 

S $3 - not in stock

M $4 - in stock

L $5 - in stock

XL $6 - not in stock

 

The price range would be $4 - $5.

 

This is my current code, instead of product.price_max I want to show the price for the last available variant:

 

{% if product.price_varies and current_variant.price != product.price_max %}
{{current_variant.price | money_without_trailing_zeros }} - {{ product.price_max | money_without_trailing_zeros }}
{% endif %}

 

Hope someone can help!

0 Likes
Highlighted
Shopify Partner
273 51 57

Hello 

From {{ product.price_min | money }} to {{ product.price_max | money }} 

for further explanation please check here https://www.shopify.in/partners/blog/collection-page-price-range

Thanks

Want to modify or custom changes on store hire me.
My Email: guleriathakur43@gmail.com
If helpful then please Like and Accept Solution.
If you happy and want to donate small, click here: Paypal
0 Likes
Shopify Partner
7 0 0

Hi, that just shows the min and max product price - it doesn't take into account whether a variant is in stock or not.  I want it to show the price range for AVAILABLE variants.

 

Thanks for the try though!

0 Likes
Shopify Partner
189 13 24

@sellingstuff 

That means you want the price in the variant select box. Am I right?

Thanks & Regards
Akshay Vaghasiya

Shopify Expert | E-commerce Consultant
Email: akshayvaghasiya84@gmail.com
Skype: akshayvaghasiya84
 - Want to modify or custom changes on store hire me .
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
0 Likes
Shopify Partner
7 0 0

Hi, if anyone else wants to do this - 

 

 

{% comment %}Fix to get last available variant price{% endcomment %}
  {% if product.variants.size > 0 and product.available %}

  {%- capture list -%}
  {%- for variant in product.variants -%}
  {% if variant.available %}    
  {{ variant.price }}
  {%- endif -%}
  {%- endfor -%}
  {%- endcapture -%}
  {% comment %}Create array of available prices{% endcomment %}
  {%- assign max_price = list | split: ' ' -%}
  {% comment %}Fix to convert strings to number so we can do a comparison{% endcomment %}
  {%- assign max_available_price_variant = max_price.last | times: 1 -%}
  {%- assign min_available_price_variant = current_variant.price | times: 1 -%}

  {% endif %}

{% comment %}Show range unless the first available price is the same as the max price {% endcomment %}
{% if product.price_varies and min_available_price_variant != max_available_price_variant %}
{{current_variant.price | money_without_trailing_zeros }} - {{ max_available_price_variant | money_without_trailing_zeros }}
{% endif %}

{% if product.price_varies and min_available_price_variant == max_available_price_variant %}
{{current_variant.price | money_without_trailing_zeros }}
{% endif %}

I'm pretty new to liquid and Shopify so there may be a better way to do this!

0 Likes