Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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?
Solved! Go to the solution
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 }}
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 }}
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!
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025