0
votes

I got a calculation which works very fine to calculate the basic price in ratio to 100 grams.

Example:

Product has a weight of 0.12kg (Weight in Shopify Backend is in kg) Product Price: 29,95

With my current formula all prices are put in ratio to 100g with this code:

<span id="perkg">{{ current_variant.price | times: 100.0 | divided_by: current_variant.weight | money }}</span>/100g

So Output is: €24,96/100g

What i now want to try, is that if the "current_variant.weight" is > 0.25kg then the output should be in ratio to 1kg instead of 100g.

Example:

Product weight 0,5kg. Product price: 14,95

Output: €29,90/1kg

Any ideas how to solve that in liquid?

1

1 Answers

0
votes

So something like this if I understand correctly:

{%- if current_variant.weight > 0.25 -%}
  {%- assign price = current_variant.price | divided_by: current_variant.weight | money -%}
{%- else -%}
  {%- assign price = current_variant.price | times: 100.0 | divided_by: current_variant.weight | money -%}
{%- endif -%}

{{ price }}