Formula in product metafield

Topic summary

Main issue: Calculate and display loyalty points based on product price, then store that computed value in a product metafield for use across products.

Current approach: Using Shopify Liquid (templating language) to derive an integer from product.price: convert price to a number (money_without_currency, remove commas, plus 0) and divide by 100, then render a sentence (e.g., “Je krijgt {{ loyalty_points }} loyaliteitspunten!”). The code snippet is central to the discussion.

Goal: Save this calculated value in a metafield (Shopify’s custom field for products) so it can be referenced in sentences without relying on a theme code block.

Problem: The author reports they cannot add a formula directly to a metafield and seeks a way to achieve this.

Latest update: The author believes a code-based solution should be possible but provides no implementation details.

Status: Unresolved; no confirmed method or outcome shared yet.

Summarized with AI on December 13. AI used: gpt-5.

Hi all

I’ve worked it out to add a custom liquid code block on my Shopify store to show the price of the product in just an integer:

{% assign loyalty_points = product.price | money_without_currency | remove: ‘,’ | plus: 0 | divided_by: 100 %}

Je krijgt {{ loyalty_points }} loyaliteitspunten!

But I would like this value, in a metafield for all my products, but I can’t seem to add a formula to a metafield.

The purpose of this metafield would be to show the value in sentences instead of the liquid code block.

Thanks for the help!

Hi,

I think this should be doable by figuring the code out. Shouldn’t be to hard.

Thanks