Displaying and Calculating metafields in Liquid

Topic summary

Displaying product/variant metafields and calculating a sale price in Shopify Liquid on product pages with variants.

  • Initial issue: Metafields wouldn’t render (e.g., product.metafields.custom.saleprice, variant.metafields.custom.var_saleprice). The if-check used product.metafields.custom.onsale without accessing its value.

  • Key fix shared: Access metafield values via .value (e.g., product.metafields.custom.onsale.value == true). This resolved the boolean check.

  • Current problems: product.metafields.custom.saleprice.value and variant.metafields.custom.var_saleprice.value return null even though values exist in admin. No root cause identified in-thread (could be definition/namespace/key/type mismatch, but not confirmed).

  • Variant behavior: Theme updates variant price on selection, but the displayed variant metafield (var_saleprice) does not auto-update, implying additional JavaScript is needed to re-render metafield output on variant change.

  • Workaround: Sale price calculated in Liquid as 25% off product.price using captures (Discount, Final) displays correctly for the initial product price, not dynamically per variant.

  • Status: Partially resolved (.value usage). Saleprice/var_saleprice nulls and dynamic variant metafield updates remain unresolved. An attached image illustrates the price/discount but isn’t essential to the solution.

Summarized with AI on January 18. AI used: gpt-5.

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 %}> {{product.metafields.custom.saleprice}}> {%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 :waving_hand:

You need to make sure you are access the value of the metafield.

The following should work.

{% if product.metafields.custom.onsale.value == true %}
1 Like

Thank you Lizk!

That was very helpful. Could I ask one more favour?

So,product.metafields.custom.onsale.value is now fine. :slightly_smiling_face:

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 %}
{{product.metafields.custom.saleprice.value}}

{%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 %}

{{ Final | money }}

{%endif%}