How to display variant title of sales price on collection page?

Solved

How to display variant title of sales price on collection page?

FileNumberDate
Excursionist
35 0 20

Hi

 

I am trying to display variant title of the sales price on collection page.

 

I am editing the 

product-price-listing.liquid

 

 

So far I have tried using below code:

 

  {% comment %} Show title of the current variant in price  {% endcomment %}
  {% if product.variants.size > 1 %}
  <div class="custom_variant_price-div"><span>Price for one </span>{{ variant.title }}</div>
  {% else %}
  <div><span>Price pr. unit.</span></div>
  {% endif %}
  {% comment %}  Show title of the current variant in price - end  {% endcomment %}

The problem I am facing is that  

 

variant.title

 

is giving me the title of the first pre-selected variant of the product. I want to show the title of the variant that is used for the sales price/price being displayed on the collection page.

 

I see there is 

variant.unit_price

Is there something like variant.unit_title?

 

ATTENTION!
Stay hydrated!
Thank you for your attention.
Accepted Solution (1)

made4Uo
Shopify Partner
3873 718 1221

This is an accepted solution.

Hi @FileNumberDate,

 

You were trying to do a short cut 😁. The code does not know which variants do you want. Try the corrected code below instead

 

{% comment %} Show title of the current variant in price  {% endcomment %}
  {% if product.variants.size > 1 %}
{% assign variant = product.variants[0] %}
  <div class="custom_variant_price-div"><span>Price for one </span>{{ variant.title }}</div>
  {% else %}
  <div><span>Price pr. unit.</span> {{variant.price | money }}</div>
  {% endif %}
  {% comment %}  Show title of the current variant in price - end  {% endcomment %}

 

In this code, we use the code below to should the variant price of the first variant

{{variant.price | money }}

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free

View solution in original post

Replies 2 (2)

made4Uo
Shopify Partner
3873 718 1221

This is an accepted solution.

Hi @FileNumberDate,

 

You were trying to do a short cut 😁. The code does not know which variants do you want. Try the corrected code below instead

 

{% comment %} Show title of the current variant in price  {% endcomment %}
  {% if product.variants.size > 1 %}
{% assign variant = product.variants[0] %}
  <div class="custom_variant_price-div"><span>Price for one </span>{{ variant.title }}</div>
  {% else %}
  <div><span>Price pr. unit.</span> {{variant.price | money }}</div>
  {% endif %}
  {% comment %}  Show title of the current variant in price - end  {% endcomment %}

 

In this code, we use the code below to should the variant price of the first variant

{{variant.price | money }}

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free
FileNumberDate
Excursionist
35 0 20

Thanks a lot @made4Uo !

I see and understand what you did there 🙂
The variant for my store setting was 

product.variants[1]


My store (Debut theme) is set up to show single price on product page, which would be:

product.variants[0]

but "bulk discount" on collection page, which is

product.variants[1]

 

Wishing you a great day!

ATTENTION!
Stay hydrated!
Thank you for your attention.