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.
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025