Hi everyone, I’m hoping someone can help me with this…
In our store, each product has a variant metafield called ‘length_cm’, where the value is a ‘decimal’. This variant metafield is used to store the item’s longest edge in cm’s.
I am trying to write a liquid statement that calculates the sum of these lengths, specifically in the cart/checkout (we’re on Shopify Plus).
Sum of variant.metafields.product_data.length_cm = 104.5
I know I have to loop over the cart items for cart-related data, but I don’t know how I can loop over the variant metafields of those items and add them all together.
I would appreciate some help if anyone has a solution?
Thank you @LitCommerce , this works perfectly and is exactly what I asked for.
Is there a way we can account for multiple quantities of the same line item? The code will only account for the single instance of the length metafield for that one line item, even though there might be 3 qty in the cart. The desired outcome would be that all line items, including their qty are added up.
e.g.
Cart contents:
Line item 1 - length_cm = 50 (qty 3)
Line item 2 - length_cm = 20 (qty 1)
The expected sum of length_cm = 170. However, the current code only calculates the sum as 70.
I’m trying to do something similar (we plant a certain amount of trees for each product purchased). Is this something I’d need to add to do differently to get this to display in the order notification email? Copying the code above and swapping in my metafield (just product level, not variant set) spits out 0 every time