How to display a message on product page only if the product has variant

Solved
MinuSak
Excursionist
28 0 9

Hello,

I want to display a message "Please select price:" on the product page only if the product has variants.

How can this be implemented, Can anyone please help?

Thanks in Advance.

0 Likes
David_Weru
Trailblazer
129 9 21

Hello @MinuSak 

 

From the current variant, this would tell you how many variants a product has:

{{variant.product.variants | size}}

 

From the current product, this would also tell you the variants a product has:

{{product.variants | size}}

 

You can use that in your logic like this:

{{variant.product.variants | size}} > 1

or..

{{product.variant.product.variants | size}} > 1

If you would like further assistance, please let me know.

LitExtension
Shopify Partner
1236 162 218

This is an accepted solution.

You can go to the file product-template.liquid and add the code:
{% unless product.has_only_default_variant %}
Please select price:
{% endunless %}
This code will help you check if the product has variant or not.
Hope it clear to you.

LitExtension - 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!
MinuSak
Excursionist
28 0 9

Thank you, but it says - Liquid syntax error: Unexpected character { in "{{ product.variant.product.variants | size }} > 1"  

i used this as code

{%- if {{ product.variant.product.variants | size }} > 1 -%}

0 Likes
MinuSak
Excursionist
28 0 9

Thank you so much, it worked...

0 Likes