For each

The For each action performs an action on every item in a list, when that action is connected to the Do this for each item option. This action functions on lists, such as line items in an order or lists returned by these actions:

After you add the For each action, select either or both of the following options:

  • Click Then to add a single action or a condition. This action is taken after all the actions performed by Do this for each item are complete.
  • Click Do this for each item to add an action to perform on every entry in the list returned by a Get action.

For example, you create a workflow that runs once a week. The workflow uses the Get order data action to retrieve orders placed during that week and applies a tag to each one. After all the tags are applied, an email is sent indicating that tagging is complete.

Example of a workflow that retrieves a list of orders placed in the past week and adds a tag to each order, then sends an email.

Considerations for using the For each action

Review the following considerations before you use the For each action:

  • The list that you use in the For each action can't have more than 100 items. If the selected list has more than 100 items, then the workflow fails and all actions following the For each action aren't taken.
  • The following actions can't follow Do this for each item:

Only one condition or action can immediately follow Do this for each item. You can add multiple additional conditions after this, but each option can only lead to a single condition or action.

For example, you create a workflow that uses the For each action. You click Do this for each item and add a condition. In this condition, and in every condition following it, only one action or condition can be added to either the Then or Otherwise options.

Example of a workflow that uses multiple conditions after Do this for each action.

Fields

The For each action contains the following fields.

Fields used in the For each action.
FieldDescription
ListRequired. The list of items to perform an action on. This can be a list returned by a Get action or a list returned by a trigger, such as a list of line items returned by the Order created trigger.

Triggers

The For each action can be used in any workflow.

Monitoring workflows

After a workflow has run, you can review its performance on the Shopify Flow Activity page. The following is true for workflows that contain a For each action:

  • The Status and Action sections apply to all the actions taken by the For each action.
  • The Run details section, including the preview of the workflow, apply only to the last action that the For each action has taken.

Templates

Add line items to Google Sheets rows when a new order is placed

When a new order is created, a For Each step in a workflow loops over each line item to add the product data to a Google Sheet row. View template

Add products with a tag to a collection in the future

At a time in the future, get all products with a certain tag and then add them to a collection. View template

Allow ordering for companies created by company account requests

Assign an ordering permission when a company is created by a company account request. View template

Cancel orders if customer placed more than 5 orders today

Cancels orders if a customer places more than five orders within a single day. It checks the number of orders placed by a customer in the last 24 hours and cancels any orders exceeding this limit, tagging the customer for potential fraud. View template

Convert a customer metafield into tags for all customers

This workflow will backfill tags onto all of your customers based on a metafield value. It runs every hour and fetches up to 100 customers that do not have a "processed" tag. For each customer, it looks at the value of a custom.test metafield and adds it as a tag. The workflow also adds a "processed" tag so that it isn't returned in the next scheduled run of the workflow. To use the workflow, you will need to change the metafield namespace and key to match a metafield in your shop. View template

Delete inactive customers

Delete customers over 5 years old that have never placed an order. View template

Delete inactive products

Delete products with no inventory that have not been updated in a year. View template

Fulfill any digital items in an order

Fulfills any items that have no physical delivery required, such as digital items, or that match a list of SKUs. Runs once for each fulfillment location (the 'fulfillment order') for a new order. View template

Hold fulfillments if a customer placed multiple orders in 24 hours

Check to see if a customer has placed multiple orders within a 24 hour period. If true, hold the fulfillments and consolidate shipping. View template

Hold orders if customer placed more than 1 order in last 24 hours

When an order is created, check if customer placed any other orders in the last 24 hours. If so, place all orders on hold. View template

Publish products with a certain tag in the future

On a date in the future, get products with a certain tag and publish them. Used Scheduled time trigger and Get product data action. View template

Release fulfillment hold on exchange items once the return is closed

When a return is closed, check if there is an outstanding balance on the order. If there is no order balance, release the exchange items. View template

Remove new product tag 90 days after the product was created

Every day, gets up to 100 products that were created more than 90 days ago and which still have the "new" tag. The workflow then removes those tags for each product. View template

Schedule products to be removed from Online Store at the specified date and time

At a single date in the future, remove products from online store by tag, id, or sku. Makes use of Scheduled time trigger, Get Product Data action, For Each loop. View template

Send B2B order invoice to multiple email addresses

Send invoices for B2B orders to multiple email addresses. This will use the email addresses saved as Metafields in a company location, if they exist, or this will first create three Metafields: extra_invoice_recipient.email1, .email2, .email3. View template

Send Order and Line Items to Google Sheets

Output each Order Line Item to a row in Google Sheets using the For Each action. View template

Tag and send a daily summary of late fulfillments

Every day, tag and send a daily email summary that counts the total number and dollar value of all orders that miss a 2 day shipping guarantee. View template

Tag customers that have a chargeback

Every hour, this workflows gets orders with chargebacks and adds a tag to the customer for the order. Makes use of scheduled time trigger, get order data, and for each loop. View template

Tag orders with associated UTM campaign

Adds tags to orders that contain the names of any associated UTM campaigns. View template

Tag unfulfilled orders older than 2 days

Every day, the workflow gets all unfulfilled orders older than 2 days and it adds a tag to the order. View template

Track product variants that are on sale using a product metafield

Sets a metafield on a product if at least one of its variants is on sale. This can be useful for tracking which products are currently on sale. View template

Can’t find the answers you’re looking for? We’re here to help.