What's your biggest current challenge? Have your say in Community Polls along the right column.

Loop through orders at specific time and take action on only those orders that contain a tag

Solved

Loop through orders at specific time and take action on only those orders that contain a tag

monnedepraetere
Tourist
9 0 1

The requirement

We want to loop through all recently fulfilled orders each hour and assess whether any orders have the tag 'delivery failed' applied. If this tag is present, we want to trigger a customer email in Klaviyo.

 

Additional info 1: the 'delivery failed' tag is automatically added to the order by our shipping app (DPD integration app) and since there's no "added tag to Order" trigger in Shopify Flow, we need to periodically go loop through the orders to check.

Additional info 2: the 'delivery failed' information should also be saved somewhere else in the order data (e.g. in custom order attribute?) as it is visible in the interface (see below image as example) however we are not sure how to access it. Therefore, we are working based on order tags. 

 

monnedepraetere_0-1686417652431.png

 

What we have tried so far

We tested the below Flow, using the 'Scheduled Time' trigger and a 'For Each' loop. The aim is to list all unfulfilled orders that were created in the last month which we then can iterate over using the 'For Each'. However, we can't get the condition in the For Each loop to check each individual order seperately: it only checks whether the 'delivery failed' tag is present in any of the listed orders, not just the individual order that we are iterating over. Therefore. the final action ('send data to Klaviyo') is performed on all the orders, not only the ones with the tag.

 

monnedepraetere_1-1686417730871.png

 

Any help is greatly appreciated!

Accepted Solution (1)

paul_n
Shopify Staff
1445 157 334

This is an accepted solution.

So first, in the query you can filter by `tag:"delivery failed"`. Then you don't need that condition at all. i suspect your condition is ill-formed but cannot tell from the overview (provide a screenshot of that if you need further trouble-shooting). In the condition, if you keep it, you need to use the "item" that is returned from the for-each loop.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 5 (5)

Digico
Shopify Partner
47 1 5

Maybe try the "WHERE" filter in Liquid which will allow to sort things by date and only select the date range needed. It will need a valid date range from input data too.

https://shopify.dev/docs/api/liquid/filters/array-filters#where

 

Talk your feedback, please,

 

François,

Digico Paris

JoesIdeas
Shopify Partner
2446 225 662

If you can't find a solution with Shopify Flow, as a backup plan you could use Order Automator app. It's an automation app for order processing tasks, but is also extendable with custom features to do stuff like what you're asking.

• Creator of Order Automator [auto tag, fulfill, connect FBA, daily jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tactics

paul_n
Shopify Staff
1445 157 334

This is an accepted solution.

So first, in the query you can filter by `tag:"delivery failed"`. Then you don't need that condition at all. i suspect your condition is ill-formed but cannot tell from the overview (provide a screenshot of that if you need further trouble-shooting). In the condition, if you keep it, you need to use the "item" that is returned from the for-each loop.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
monnedepraetere
Tourist
9 0 1

Many thanks, that worked. The option to query on tags is very useful, somehow I missed this in the docs

AbdullahShahz03
Shopify Partner
14 0 2

Thats is done in this case, but I have the same problem as well.

 

I need to delete items from my store if it is older than 18 months skip the product that have all variant inventory  equal to 0.