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.
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025