Conditions in Shopify Flow

In Shopify Flow, conditions are used to determine what path to follow in a workflow, usually to control whether an action is taken. When you set a condition, you choose a data field to check (such as a product title), a logical operator (such as equal to), and a value to check against (Blue jeans).

Example conditions

Check if at least one item in a list matches a condition

This example displays a typical condition that checks if at least one item in a list matches a certain value.

In this case, the condition checks if one of the products in an order has a tag of presale. To build this condition, you would choose order / lineItems / product / tags. By default, Flow chooses at least one of as the logical operator:

If at least one of order / lineItems:
  If at least one of lineItem_item / product / tags
    tags_item
    is equal to
    presale

The at least one of parts are list operators and are used to handle matching across multiple list items. The is equal to part is a field-level operator that determines whether a single list item matches.

Check if none of the items in a list match a condition

This example displays a typical condition that checks if none of the items in a list match a certain value. One common problem to consider is that lists can be empty. When a list is empty, the condition will be handled by the list operator (in this case none of).

In this case, the condition checks if none of the product tags is equal to foo:

If none of product / tags:
  tag_item
  is equal to
  foo

The condition will return true if (1) there are no product tags or (2) none of the tags are foo. Otherwise, it will return false.

Check if an item in a list matches multiple criteria

This example displays a typical condition that checks if a least one item in a list matches two separate criteria.

In this case, the condition checks if one of the products in an order has a tag of presale and if it has a productType of clothing.

If at least one of order / lineItems:
  If at least one of lineItem_item / product / tags
    tags_item
    is equal to
    presale
  AND
  If lineItem_item / product
    productType
    is equal to
    clothing

To build this condition, you should:

  1. Choose order / lineItems / product / tags for the first criteria.
  2. Choose to Add criteria for same item on the lineItems list. Note: Choosing the wrong list item here is a common mistake.
  3. Choose lineItems_item as the top level object and then product / productType` for the second criteria. Note: Choosing the wrong object here is also a common mistake.
  4. Choose AND to combine the two criteria.
  5. Enter the values presale and clothing for the two criteria.

Data types used with Flow

The first value in any Flow condition is data taken from your store, and is drawn from the GraphQL Admin API.

Flow supports the following kinds of data:

  • Float: Float values are numbers with a decimal amount. For example, 4.25.
  • Integer: Integer values are whole numbers that don't have a decimal amount. For example, 42.
  • Date: Date values are numerical representation of the date. For example, 01012021.
  • String: String values are text. Comparisons using string values aren't case sensitive.
  • Boolean: Boolean values are either true or false.
  • Enum: Enum values are sets of data that allow for a variable to be a set of predefined constants.

Logical operators

Logical operators define how your condition is applied. Conditions can check simple properties such as whether an order's total is above a certain amount, or whether a customer accepts marketing. Logical operators can also check for more complex properties.

Operators can be either field-level operators, such as equal to or not equal to, or list operators, such as at least one of or none of.

Field-level operators

Field-level operators are used to compare two values. Flow can use the following operators:

Equal to

Equal to compares values to check whether they're the same. In the following example, the value for order.currentTotalDiscountsSet.shopMoney.amount is retrieved from your store data and compared to the second value, 50.

Example of a workflow that uses the equal to logical operator to cancel an order if the retrieved data is equal to 50

If the first value equal to 50, then the condition is true. The order is canceled.

Not equal to

Not equal to compares values to check whether they are not the same. In the following example, the value for order.currentTotalDiscountsSet.shopMoney.amount is retrieved from your store data and compared to the second value, 50.

Example of a workflow that uses the not equal to logical operator to cancel an order if the retrieved data is not equal to 50

If the first value is equal to 93, then the condition is true. The order is canceled.

Greater than and Greater than or equal to

Greater than and Greater than or equal to compare values to check whether the first value is greater than, or greater than or equal to, the second value. In the following example, the value for order.currentTotalDiscountsSet.shopMoney.amount is retrieved from your store data and compared to the second value, 50.

Example of a workflow that uses the greater than logical operator to cancel an order if the retrieved data is greater than to 50

If the value taken from your store is 137, then the condition is true, because 137 is greater than 50. The order is canceled.

Less than and Less than or equal to

Less than and Less than or equal to compare values to check whether the first value is less than, or less than or equal to, the second value. In the following example, the value for order.currentTotalDiscountsSet.shopMoney.amount is retrieved from your store data and compared to the second value, 50.

Example of a workflow that uses the less than or equal to logical operator to cancel an order if the retrieved data is less than or equal to 50

If the value taken from your store is 47, then the condition is true, because 47 is less than or equal to 50. The order is cancelled.

At least one of

At least one of operator checks whether the field is equal to any value in the provided list. The values to be checked must be entered individually and followed by the enter key (similar to tags). Using At least one of on a blank array results in a false evaluation. In the following example, the value for order.lineitem.product.title is retrieved from your store data and compared to the second set of values: pineapple, guava, kiwi.

Example of a workflow that uses the At least one of logical operator to cancel an order if the retrieved data includes pineapple, guava, or kiwi

If the value taken from your store is guava, then the condition is true, because guava is included in the array pineapple, guava, kiwi. The order is cancelled.

Not any of

Not any of operator checks whether the field is not equal to any of the values in the provided list. The values to be checked must be entered individually and followed by the enter key (similar to tags). In the following example, the value for order.lineitem.product.title is retrieved from your store data and compared to the second set of values: pineapple, guava, kiwi.

Example of a workflow that uses the not any of logical operator to cancel an order if the retrieved data does not include pineapple, guava, or kiwi

If the value taken from your store is raspberry, then the condition is true, because raspberry isn't included in the array pineapple, guava, kiwi. The order is cancelled.

Includes

Includes compares values to check whether any of the first value input includes the data in the second value input. In the following example, the value for order.lineitem.product.title is retrieved from your store data and compared to the second value, scrape.

Example of a workflow that uses the includes logical operator to cancel an order if the retrieved data includes the string scrape

If the value taken from your store data is skyscraper, then the condition is true, because the exact string scrape is included in the string skyscraper. The order is cancelled.

Does not include

Does not include compares values to check whether any of the first value input does not include the data in the second value input. In the following example, the value for order.lineitem.product.title is retrieved from your store data and compared to the second value, scrape.

Example of a workflow that uses the does not include logical operator to cancel an order if the retrieved data does not include the string scrape

If the value taken from your store data is scrap-metal, then the condition is true, because the exact string scrape isn't included in the string scrap-metal. The order is cancelled.

Starts with

Starts with compares values to check whether the first value starts with the data in the second value. In the following example, the value for order.shippingAddress.country is retrieved from your store data and compared to the second value, United.

Example of a workflow that uses the starts with logical operator to cancel an order if the retrieved data starts with the string United

If the value taken from your store is United Kingdom, then the condition is true, because the string United starts the string United Kingdom. The order is cancelled.

Does not start with

Does not start with compares values to check whether the first value does not start with the data in the second value. In the following example, the value for order.shippingAddress.country is retrieved from your store data and compared to the second value, United.

Example of a workflow that uses the does not start with logical operator to cancel an order if the retrieved data does not start with the string United

If the value taken from your store is Canada, then the condition is true, because the string Canada does not start the string United Kingdom. The order is cancelled.

Ends with

Ends with compares values to check whether the first value ends with the data in the second value. In the following example, the value for order.lineitems.product.title is retrieved from your store data and compared to the second value, last-available.

Example of a workflow that uses the ends with logical operator to cancel an order if the retrieved data ends with the string last-available

If the value taken from your store is athletic socks last-available, then the condition is true, because the string athletic socks last-available ends with the string last-available. The order is cancelled.

Does not end with

Does not end with compares values to check whether the first value does not end with the data in the second value. In the following example, the value for order.lineitems.product.title is retrieved from your store data and compared to the second value, last-available.

Example of a workflow that uses the does not end with logical operator to cancel an order if the retrieved data does not end with the string last-available

If the value taken from your store is athletic socks new, then the condition is true because the string athletic socks new does not end with the string last-available. The order is cancelled.

Null or empty operators

Empty or does not exist

Some fields in your data can be empty. For example, order.cancelReason will return null if an order isn't cancelled. Use empty or does not exist if you want to return true when a field is empty or null and false if it is present.

Not empty and exists

Some fields in your data can be empty. For example, order.cancelReason will return null if an order isn't cancelled. Use Not empty and exists if you want to return true when a field is not empty and false when it is empty.

List operators

List operators are combined with field-level operators to allow you to check conditions on data included in lists.

As in the "at least one" example, you might want to check if an order contains a specific product (located in order.lineItems) with a specific tag (a list under order.lineItems.product.tags). In both cases, the example uses the at least one of list operator.

Flow provides 3 operators for working with lists: At least one of, None of, and All of.

At least one of

Most conditions with lists will want to use At least one of. This operator will return true if any of the items in the list match the condition. For example, if you want to check if an order contains a product with a specific tag, you would use At least one of. When the list is empty, or when the condition isn't met, the condition will return false.

None of

In some cases, you might want to check if a list does not contain an item. The best way to build this condition is to change the list operator to None of. This operator will return true if none of the items in the list match the condition. And importantly, if the list is empty, it also returns true. For example, if you want to check if a product does not contain the tag presale, you would use None of product tags is equal to presale.

All of

In limited cases, you might want to check if all items in a list match a condition. For example you might want to check if all items in an order have a specific product vendor called Acme. For this, you would use All of order line items have a product.vendor equal to Acme.

Ordering conditions

You can create workflows that have multiple conditions, each of which can result in different actions. The order of the conditions matters. The check for conditions starts at the beginning of the workflow and proceeds systematically through each condition. The check stops when a condition is met.

Combining multiple criteria in one condition

When building a condition, you can set several criteria. You can choose how this separate criteria should be combined.

If all conditions are met

Selecting If all conditions are met results in a true response only if every criteria that you set is true. This is like an AND statement in programming.

For example, you create a workflow to tag customers that are located in Canada and spend more than $500 on a single order.

Example of a workflow that uses the and condition

The workflow tags the customer only if the customer is located in Canada and they spend more than $500 in the order. If either of these conditions are false, then the customer isn't tagged.

If any conditions are met

Selecting If any conditions are met results in a true response if any one of the criteria that you set is true. This is like an OR statement in programming.

For example, you create a workflow to tag orders that are considered high or medium risk.

Example of a workflow that uses the or condition

The workflow tags the order if it is either high or medium risk. As long as one of those conditions are true, the order is tagged.

Combining conditions and actions

You can combine conditions together to make one large condition. When conditions are combined, all conditions must be met for the whole condition to be true. If any condition is not met, then the whole condition is false. In the following example, the customer must accept marketing materials and the total price of the order must meet a certain threshold.

Example of a workflow that checks a customer's total spend amount and adds tags

Similarly, you can combine actions together so that multiple actions can run. This example uses multiple conditions to check whether a customer is eligible for a loyalty program based on the total amount that they have spent in the store. In the example above, the following conditions are checked in the order in which they are displayed:

  1. If the total price is greater than $1000 and the customer agrees to accept marketing, then tag them with the Gold tag.
  2. If the total price is less than $1000 but more than $500 and the customer agrees to accept marketing, then tag them with the Silver tag.
  3. If the customer has spent more than $200 and the customer agrees to accept marketing, then tag them with the Bronze tag.

Static and dynamic data in conditions

Typically, the second value in a condition is a static, manually-entered value (such as product.title == "your title"). This value remains the same every time the workflow runs.

You can also use dynamic values if the field for the second value displays a </> symbol. Dynamic values are drawn from your store data every time the workflow runs. To use a dynamic value, click the </> symbol and select the value you want to check against. Dynamic values aren't available for all fields.

For example, you create a workflow that tags an order if the country in the order's billing address matches the country in its shipping address.

Example of a workflow that tags an order using RHS data to check that a customer's billing and shipping country are the same.

In this example, both the first and the second values are drawn from your store's data, rather than manually specifying a static string to check against for the second value. If the country in the billing address provided by the customer is the same as the country the customer provided in the shipping address, then the condition is true, and the order is tagged.

You might occasionally need to use dynamic data that is the wrong type. For example, you might need to compare a number stored as a string with another number. In this case, you can use the Run code option to convert the data to the correct type.

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