How do I calculate with metafields in custom liquid?

Topic summary

A user seeks help performing mathematical calculations using product metafields in custom Liquid code. Specifically, they want to subtract a metafield value (markenpreistest) from the product price and display the result in a money format.

Proposed Solution:

  • Assign the metafield value using the metafield_text filter
  • Assign the product price to a variable
  • Perform subtraction and apply the minus filter
  • Format the result using the money filter

Additional Context:
Another participant references their approach for complex calculations involving custom sizes and prices, mentioning a square meter calculator example, though the specific implementation details and link appear corrupted in the thread.

The discussion remains technical and focused on Liquid syntax for metafield arithmetic operations.

Summarized with AI on November 10. AI used: claude-sonnet-4-5-20250929.

Hello guys,

I want to do this math tasks with this fields in custom liquid:

{{product.metafields.custom.markenpreistest | metafield_text}}

minus

{{product.price | money}}

how i have to write the code, so this works?

{% assign markenpreistest = product.metafields.custom.markenpreistest | metafield_text %}
{% assign price = product.price | money %}

{% assign result = markenpreistest | minus: price %}

The result is: {{ result }}

1 Like

This solution is how we do complex calculations for adding custom sizes and prices.

This this example where we have a square meter (sq/m or sqm calculator) or calculate price by length calculator.

https://quickbar.ca/products/type-5