I am building a very simple points program using Shopify Flow.
I calculate the amount of points I get in a loop (because I have a condition that I need to check for each item) and add the result of my points calculation to a metafield. I want to take into account the previous value of the metafield. I thought of storing the intermediary result and then passing that back to the loop, but I do not know how.
This can be problematic though if there are multiple items in order and there would be a bunch of MF updates fired in succession …
So, instead of looping over line items with Flow action, you can do one metafield update, but do looping in liquid code. Kinda like this (I just used arbitrary condition in if – use yours…) (not fully tested though! : )
{%- liquid
assign mf_value = order.customer.kerstpunten1.value | default: 0
for item in order.lineItems
if item.product.tags contains "tag"
assign mf_value = mf_value | plus: item.originalTotalSet.shopMoney.amount
endif
endfor
-%}
{{ mf_value }}