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