Multiply Metafield by quantity on Checkout Page

Topic summary

Goal: show a product metafield value in the cart, multiply it by each line item’s quantity, and display a separate total at the bottom (independent of the cart subtotal) in the Shopify Dawn theme.

Key technical points:

  • Metafield = custom data on a product (e.g., custom.length_in).
  • cart.items loops line_item objects; access the product via item.product.

Guidance provided:

  • In the loop, reference item.product.metafields.custom.length_in instead of product.metafields… (product is not in scope on the cart page).
  • Output the running total with {{ length_in }}.
  • Place display code near the line item properties area in Dawn (main-cart-items.liquid), noting conditional logic may hide that section (e.g., item.product.has_only_default_variant checks). Links to specific lines in the Dawn repo were shared.

Latest update:

  • The current {{ length_in }} sums across the cart but doesn’t first compute per-item values. The requester needs: (1) per-item metafield × quantity, then (2) a subtotal of all items’ results.

Status: unresolved/open. Next step is to adjust loop logic to compute a per-item value and accumulate a separate total, then render it in the cart.

Summarized with AI on February 1. AI used: gpt-5.

In the cart under the product description, I want to show the number stored in a metafield and then multiply the number by the quantity purchased. I am having problems displaying this metafield in the Cart on Dawn theme. I can display the metafield on a product page, but I can’t see the information in the cart.

Then, at the bottom of the page, I want to display the total of the metafield quantities (separately from the subtotal).

I have this but it isn’t returning anything. Maybe I don’t know where to put it?

{%- assign length_in = 0 -%}

{%- for item in cart.items -%}

{%- assign length_in = length_in | plus: product.metafields.custom.length_in | times: item.quantity -%}

{%- endfor -%}

Your variable and filter use is sound.

However you are referencing a non-existent product when you are in an cart.items loop that is referencing item (a line_item object). There is no product as it’s not on a product page or in a collection loop.

Use **item.**product.metafields.custom.length_in in your plus filter addition.

Read through the cart code to notice how when it needs a deeper product property it goes through the item object chain to the product object it’s based on.

To output your length_in use: {{ length_in }}

For additional info display in dawn you’d want to put it in the code near the line item properties area.

https://github.com/Shopify/dawn/blob/main/sections/main-cart-items.liquid#L133

Keeping in mind the higher display logic that may make that entire area not show:

.. if item.product.has_only_default_variant == false…

https://github.com/Shopify/dawn/blob/main/sections/main-cart-items.liquid#L119

1 Like

Thank you!

I am putting this code in the wrong place. The {{ length_in }} is calculating for the total quantity in my cart, not for the quantity of each item first.

I need it to do two things:

  • calculate by item quantity

  • add subtotal of all of those

Is that possible?

Thank you