show cheapest base price on categories

jc1337
New Member
6 0 0

Hello

on categories we see the price per kilogram for example for a product. It says "from xy€/kg". But it is not the cheapest kg-price which is shown, it shows the base price for the first product variant. How can I change this?

See screenshot of product in category, with a price from 11,25€/kg and a variant of the product itself where price is 10,31€/kg

jc1337_0-1624375577148.png

jc1337_1-1624375591661.png

In the template I found this file: product-unit-price.liquid
it says: From {{ product_variant.unit_price | money }}
this must be the one to change, but I dont know to what I should change it

To solve the problem I could just change the order of all variants and have the cheapest kg-price as the first variant, but this doesnt make sense, right

Thanks for helping!

0 Likes
jc1337
New Member
6 0 0

I think I was wrong witht he template file

I think the correct file is product-card.liquid

{%- if current_variant.unit_price.size > 0 -%}
        <li>
          {% include 'product-unit-price', product_variant: current_variant, wrapper_class: "product-card__base-price" %}
        </li>
        {%- else -%}                        
               
          {% if product.compare_at_price > product.price %}
            {% comment %}
              Product is on sale
            {% endcomment %}
            {% if product.price_varies %}
              {% assign sale_price = product.price | money_without_trailing_zeros %}
              {{ 'products.product.on_sale_from_html' | t: price: sale_price }}
            {% else %}
              <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
              <s class="product-card__regular-price">{{ product.compare_at_price | money_without_trailing_zeros }}</s>

              <span class="visually-hidden">{{ 'products.product.sale_price' | t }}</span>
              {{ product.price | money_without_trailing_zeros }}
            {% endif %}

          {% else %}
            {% comment %}
              Not on sale, but could still have varying prices
            {% endcomment %}
            {% if product.price_varies %}
              {% assign price = product.price | money_without_trailing_zeros %}
              {{ 'products.product.from_text_html' | t: price: price }}
            {% else %}
              <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
              {{ product.price | money_without_trailing_zeros }}
            {% endif %}

          {% endif %}
          {%- unless product.price_varies -%}
            {%- if current_variant.unit_price_measurement -%}
              {% include 'product-unit-price', product_variant: current_variant, wrapper_class: "product-card__unit-price" %}
            {%- endif -%}
          {%- endunless -%}
        
        {%- endif -%}

at some part it just use the first variant (maybe "current_variant"?) but I want the cheapest one to be shown
hope somebody could help

0 Likes