Update product metafield without replacing existing values in list of single line texts

Topic summary

A user needed to update a product metafield in Shopify Flow by adding new values to an existing list of single-line text entries without replacing the current values. The workflow checks products for specific variant metafield values and updates the corresponding product metafield when matches are found.

Solution provided:

  • Use Liquid code in the “Update product metafield” action to append new values
  • Reference the existing metafield values and iterate through them using a for loop
  • Add the new value at the end of the array

Code structure:

[
{% for v in product.metafieldName.value %}
 {{ v | json }} ,
{% endfor %}
{{ "New value" | json }}
]

The solution was tested successfully and resolved the issue on the first attempt. The helper referenced Shopify’s metafield list formatting documentation for additional guidance.

Summarized with AI on October 25. AI used: claude-sonnet-4-5-20250929.

I am using flow to:

  • check products for specific variant metafield values
  • update product metafield for items matching the variant metafield values

(emphasis added to hopefully preempt confusion)

So far I can do the above. However, what I DON’T wish to do (and what the existing options do by default) is remove any of the existing values from the product metafield when it’s updated – I just want to add a new value to the list of single line text values.

I’ve found some other threads that kind of did something similar, but the use case was different enough that I wasn’t able to figure out how to convert it to my needs. They’re also mostly from 2023, and things have changed.

Based on one of those threads, I’ve added a step to log the existing product metafield values, and presumably I just need to add some liquid to the “update product metafield” action to add the new value to the existing values. I just don’t know how to write that, as coding is not in my skillset. Can anybody help me out?

1 Like

Of course you can do that – “Update MF” takes liquid expressions as arguments (and you can reference old MF value there).
If you want to add a single text value to a list of text values, then this should be similar to:

[
{% for v in product.tagReplacement.value %}
 {{ v | json }} , 
{% endfor %}
{{ "New value" | json }}
]

In my test environment I have a product metafield which is a list of single-line text values – custom.tag_replacement which is aliased in Flow to tagReplacement

I am using “new value” to add, you can use a variable here.

Formatting guidelines are here:


if my post is helpful, please like it ♡ and mark as a solution -- this will help others find it
1 Like

Thank you! Worked perfectly on the first try.