Update Metafield by counting number of purchased products

Topic summary

Goal: Increment a customer metafield with the quantity from each new order to maintain a running total of purchased items in Shopify Flow.

Issue: The author couldn’t retrieve the current metafield value in Flow before adding the new quantity (screenshot provided but not essential to the solution).

Key clarification: Flow cannot access metafields directly by namespace/key the way Storefront does. Instead, you must access customer metafields via order.customer.metafields.

Workable approach: Filter the customer metafields collection by namespace and key (e.g., using Liquid’s where filter) to find the target metafield, then read its .value to compute the new total. A brief Liquid example was provided showing how to select the metafield and output its value.

Status: A practical workaround was shared (loop or where filter) to read the existing value; no explicit confirmation of implementation success, but the guidance is actionable.

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

Hi everyone,

I am fairly new to liquid so I hope this will be a quick answer for someone. I am looking to do the following in Shopify flow.

I currently have a metafield that will be updated every time a customer purchases an item. For instance, they have purchased 10 items in the past and have a new order of 10, the Shopify Flow will update the metafield to 20.

This is currently where I am stuck. As I cannot seem to find the the current metafield value before adding the new order quantity.

You can’t access metafields that way in Flow yet. Storefront does something special to fetch metafields values by namespace. In Flow, you loop over order.customer.metafields … FYI if you click add variable and choose the metafield value it will show you the loop part.

Another way to do it is using where:

{% assign my_mf = order.customer.metafields | where: “namespace”, “custom” | where: “key”, “pledgedcards” | first %}
{{ my_mf.value }}