Faisal Ali
Faisal Ali

Reputation: 23

How can i get total base measurements in shopify theme file

I want to display "total base measurement" on the cart page. How can I achieve this one?

sh

Upvotes: 0

Views: 523

Answers (1)

Bilal Akbar
Bilal Akbar

Reputation: 4950

Product measurements are part of variant object. If your theme does not support this, you can follow this Shopify guide to display unit prices. However, latest Shopify supported themes display this information on Product as well as Cart pages. Relevant code snippet from Shopify Debut theme, that shows unit prices on Cart page.

{%- comment -%}
    Markup template for unit price
{%- endcomment -%}
<div {% unless item.unit_price_measurement %}class="hide" {% endunless %}data-unit-price-group>
    <dt>
        <span class="visually-hidden visually-hidden--inline">{{ 'products.product.unit_price_label' | t }}</span>
    </dt>
    <dd>
        <span class="price-unit-price">
        {%- capture unit_price_separator -%}
            <span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
        {%- endcapture -%}
        {%- capture unit_price_base_unit -%}
            {%- if item.unit_price_measurement.reference_value != 1 -%}
                {{- item.unit_price_measurement.reference_value -}}
            {%- endif -%}
            {{ item.unit_price_measurement.reference_unit }}
        {%- endcapture -%}
            <span data-unit-price>{{ item.unit_price | money }}</span>{{- unit_price_separator -}}<span data-unit-price-base-unit>{{- unit_price_base_unit -}}</span>
        </span>
    </dd>
 </div>

This is how the Cart page looks

enter image description here

Upvotes: 1

Related Questions