I have a question about selecting product’s variants and looking forward to getting some help:
On the price section, I’ve set when the price is equal to 0, display ‘ENQUIRE FOR PRICE’ instead of 0, the code is below:
{%- if selected_variant.price == 0 -%}
ENQUIRE FOR PRICE
{%- else -%}
{{- selected_variant.price | money -}}
{%- endif -%}
However, it only works when I enter the page with a selected variant that has a price equal to 0, for example in this Link .
If I enter the page with this link, it will display the product with a non-zero price first, then when I select a product price equal to 0, the code above doesn’t work. This situation also happening on my stock variable and 'Contact for preorder button, I’ve attached a demo video please check.
I’m assuming it’s related to some javascript code in my theme, that refreshed the product information section when I selected variants. Could anyone please give me some advice about where should I work on?
I’m assuming it’s related to some javascript code in my theme, that refreshed the product information section when I selected variants. Could anyone please give me some advice about where should I work on?
This will vary wildly between themes and is an advanced subject even if you have coding experience.
Otherwise a clunky workaround is to make an event handler that checks the variant parameter and compares that to a hidden message field with matching variant ids to display that message.
Or just full reloads the page every time the option is changed.
Hi @LitExtension , Thanks for your prompt and helpful response.
I’ve tried your code and it works very well.
I would like also to change the stock detail to ‘PLEASE CONTACT US FOR ETA OF THIS ITEM OR MAKE A PRE-ORDER AT A DISCOUNT PRICE TODAY!’ when I select a variant that price is zero.
Sorry about the confusion, but I mean how can I change the stock text when switching to a product that’s unavailable.
For example on this image https://imgur.com/a/CdPkXOf Stock and the disabled button at the bottom shares the same language setting which is ‘CONTACT FOR PREORDER’, when the user selects a product that is out of stock. I want after the stock shows: PLEASE CONTACT US FOR ETA OF THIS ITEM OR MAKE A PRE-ORDER AT A DISCOUNT PRICE TODAY!
And the button that is disabled still shows CONTACT FOR PREORDER, is that possible to do?