Add a tag to orders where more than one item contains a certain tag (i.e. FREEGIFT)

I’m looking to set up a flow that:

When an order is placed
Check the line items in the order
If more than one of the line-items in the order has a tag of FREEGIFT
Add a tag to the order (I.e. ‘Review’)

The method of finding the line-items could be different if necessary. We could use the item names, a metafield, the items being in a same collection – we’re flexible. BUT I don’t know how to pair to a quantity of data on that line-item being greater than one across all the products in the order, and only adding the tag on that condition. Instead everything I come up with seems to keep the logic divorced.

You’re talking about looking at the tags on the products that are associated to the line items? You’d probably need some custom graphql to pull that in since you can’t loop over the line items and retreive the product from within the loop. Then probably a run code step to loop over those products and count up the number with that tag.

Doesn’t a ‘for each’ get me that loop? If I do:

Order created
For each item in order.lineitems
Do this for each item
Check if [whatever works] (Name includes ‘free’ or something will work)
(?) … (This is where I don’t know how to get to a count of the matches)
Then if count = >1
Add order tag

And yeah – to confirm, looking at product tags, or I could use the name, or metadata at the product or variant level. A # of options could work for what I’m matching against.

If you need to count multiple lineItems based on data for each of those lineitems, you should use Run code. Something like

Order created

Run code

If (has more than 1 free gift- output from run code)

Add order tag

We have sample code for counting line items here:

https://github.com/Shopify/flow-code-examples/tree/main/run-code-examples/order-sum-products

It’s looking for certain titles, so you’ll need to add in your tag logic instead.