Price per unit: Link price to variants

New Member
3 0 0

Hey everyone!

Some background information:

I have a shop in Germany and here it's obligatory to show the price per unit. Recently, Shopify did include this function in the backend and provided some snippets which have to be placed in the themes' code in order to be displayed:


If you copy and paste them into the code nothing happens. With a little addition (for loop)  found on the board the code looks like this:


            {% for variant in product.variants %}
            {%- if variant.unit_price_measurement -%}
   ({{ variant.unit_price | money }}
  {%- if variant.unit_price_measurement.reference_value != 1 -%}
    {{- variant.unit_price_measurement.reference_value -}}
  {%- endif -%}
  {{ variant.unit_price_measurement.reference_unit }})
{%- endif -%}
{% endfor %}
And on the product page:
Bildschirmfoto 2019-10-13 um 19.29.55.png
Looks good! 
The problem now is the following: If I have two or more variants, the price per unit is displayed for all variants:
Bildschirmfoto 2019-10-13 um 19.32.17.png
My goal: I want to link the price per unit which is displayed in brackets to the variants. When somebody clicks on 300ml it has to show the first price/unit and if someone clicks on 460ml it has to show the second price/unit. It should change just like the product price itself.
Just like in this example:
Does anyone have an idea how to code this? I appreciate every suggestion!

please share a store url

Thanks & Regards
Perennial Solution

Would like to add new functionality or customize an existing one, please hire us.
If helpful then please Like and Accept Solution .
Skype: infoperennialsolution