Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello,
I need a flexible price that is always based on the variant and weight selected. Hence I need to display below my normal price a custom liquid that calculates the price divided by the weight times 100 (for the 100g).
I tried it like the following code in a custom liquid field on the product page:
{% assign price_per_100g = variant.price | divided_by: variant.weight | times: 100 %} {% assign price_per_100g = price_per_100g | money %} <p>Price per 100g: {{ price_per_100g }}</p>
Somehow it won't display anything besides the Price per 100g. I am using the Dawn theme, but this shouldn't be theme specific I guess.
Hi @huks
Can you please check the code below, It will work:
{% for variant in product.variants %}
{% if variant.weight > 0 %}
{% assign weight_in_grams = variant.weight %}
{% assign price_per_100g = variant.price | times: 100 | divided_by: weight_in_grams %}
<p>Price per 100g: {{ price_per_100g | money }}</p>
{% else %}
<p>Price per 100g: Not Available</p>
{% endif %}
{% endfor %}
Hi @huks
If the solution presented meets your needs and effectively addresses your query, I encourage you to accept it as the chosen answer. This will acknowledge your support and aid fellow community members in identifying reliable and effective solutions for their similar concerns.
Thank you.
Thanks for your help & sorry for the late response. Unfortunately it's not 100% the solution. It now writes down all prices at once, I need only the price for the variant selected.
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025