Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hello All. I have Product Pages (using GemPages but not relevant - can insert Liquid easily) and in a Liquid code block I wish to display my metafields :
product.metafields.custom.saleprice and/or variant.metafields.custom.var_saleprice (for variant?)
However no matter what I try metafields do not appear (except obvious fields like {{product.price}} )
{% if product.metafields.custom.onsale == true %}
<span style="color: rgb(20,20,20);font-size: 14px">{{product.metafields.custom.saleprice}}</span>
{%endif%}
My end goal is to be able to Calculate saleprice as 25% off the product.price
Any suggestions would be much appreciated. Thanks kindly,
Hi there 👋
You need to make sure you are access the value of the metafield.
The following should work.
{% if product.metafields.custom.onsale.value == true %}
To learn more visit the Shopify Help Center or the Community Blog.
Thank you Lizk!
That was very helpful. Could I ask one more favour?
So, product.metafields.custom.onsale.value is now fine. 🙂
However, no matter what I try : product.metafields.custom.saleprice.value and variant.metafields.custom.var_saleprice.value are null. And yes, I have double checked in the Products that these have values.
----
{% if product.metafields.custom.onsale.value == true %}
<span style="color: rgb(20,20,20);font-size: 14px">{{product.metafields.custom.saleprice.value}}
</span>
{%endif%}
----
And Finally.. this code works 100% However my Product has Variants and when I Select a Variant it automatically updates the Variant Price on the page. However it does not automatically update (display) what should be : variant.metafields.custom.var_saleprice.
{% if product.metafields.custom.onsale.value == true %}
{% capture Discount %}
{{ 0.25 | times:product.price }}
{% endcapture %}
{% capture Final %}
{{ product.price | minus:Discount }}
{% endcapture %}
<span style="color: rgb(20,20,20);font-size: 22px">{{ Final | money }}</span>
{%endif%}