Understanding conditions in Shopify Flow
A condition is a step in a workflow where a decision is made about how to proceed based on whether a set of criteria has been met. Each condition step has 2 possibilities: True, when the criteria have been met, and False when the criteria haven't been met. If you don't define a next step for either of the possibilities by choosing another condition or action, then the workflow run stops.
For example, if your workflow is triggered when an order is created, then a condition could check whether a specific AFFILIATE10 discount code was used on the order. If it was, then the True option could lead to an action that sends an email to the affiliate to let them know their code was used. If it wasn't, then the False option could be empty, indicating that nothing further happens and the workflow run ends.
A workflow can have any number of conditions, depending on the complexity of your workflow. Conditions can also connect to other conditions or actions depending on what you want the workflow to do. Conditions can be set up to connect in sequence (for example, if condition A is true, then check for condition B; if A is false, then check for C), or you can set them up to occur simultaneously as part of the same step (for example, check if A or B or C is true).
On this page
Crafting conditions for your workflow
Unlike a trigger or an action, which you can select from a preset list of available options in Shopify Flow, conditions are crafted from scratch by selecting variables, logical operators, and values to create the conditional statement:
- A variable is a placeholder that defines the data that the condition is using. For example, if a condition wants to check for a specific discount code on an order, then the variable would be
order.discountCode. Variables use GraphQL Admin API dot notation. - A logical operator indicates how the workflow should determine whether the condition is met. Logical operators can apply at the variable level, or when multiple variables are included as part of the overall condition criteria:
- Variable-level options include field-level operators such as Greater than or Starts with, or list operators such as At least one of or All of.
- Condition-level options include AND, meaning all variables must be true in order for the condition to be considered true overall, or OR, meaning at least 1 variable must be true in order for the condition to be considered true overall.
- A value is the actual information that the variable is looking for. For example, if the specific
order.discountCodethat you want the workflow to check for is AFFILIATE10, then that would be the value to include as part of the condition.
As you select your variables and operators, the condition step in the Shopify Flow canvas updates to reflect your conditional statement in plain language, so you can double-check whether the condition you're building is formatted correctly. You can click Add description to overwrite the default conditional statement with your own written description.
Learn more detailed information about elements of conditions in Shopify Flow.
Understanding variables in conditions
When crafting a condition step in a workflow, the first step you're prompted to take is to Add a variable. But, what is a variable?
In Shopify Flow, a variable is a placeholder that indicates the data being used by the condition in the workflow. When a condition reads "If A is greater than 10...", the A part is the variable. Choosing a variable for a condition is essentially telling the condition specifically what data to evaluate.
Variables are formatted using the GraphQL Admin API dot notation. You don't need to be proficient with the API to create workflows with the Flow app, but a basic understanding of variable names and their definitions can help you build the specific workflow logic that you want.
To understand what data a variable represents, consider the following information about variables:
- How to read variable dot notation.
- Understanding data requirements for variables.
- Locating the correct variable during a search.
Tip: Get help with variables from the Dev Docs Assistant
If you're not sure which variable to select when building your condition, then consider asking the Shopify Dev Docs Assistant for advice. The Dev Docs Assistant has access to all documentation regarding the GraphQL Admin API, and can offer suggestions for how to format a condition in Shopify Flow:
- Go to Shopify Dev Docs.
- Click Ask Assistant to open the chat panel.
- In the message field, enter your request, such as "Which variable should I use in Shopify Flow if I wanted to access the customer tag data when my trigger starts with "Order created"?".
- Press Enter or click
.
Reading variable dot notation
When selecting variables, you'll notice that they're formatted as keywords separated by periods, such as order.customer.tag. This format is indicating the steps that the API takes to get to the data that you want to use. Each 'step' of a variable is separated by a period, and the path to the data is read from left to right. Variables can differ in length depending on where the data is stored in the API and the path the workflow takes to get there.
For example:
order.email: Checks the email address associated with the customer for the order. It's similar to how you might click an order and then check the email address on the order details.refunds_item.staffMember.name: Checks the order for an item refund, goes to the staff member information associated with that refund, and checks the full name of that staff member.
When choosing a variable, consider how you might navigate the Shopify admin to find the information that you want. It's likely that the API might need to take a similar path, which can help you determine how your variable might be formatted.
For example, if you're reviewing a new order and want to know what RFM group the customer associated to the order is in, then you might think to click the customer name on the order to be redirected to the customer's details page in the Shopify admin, and then you might check the customer's analytics summary to read what value is displayed in the RFM group column.
The variable that you'd use to return the same data in Shopify Flow would use a similar path: order.customer.statistics.rfmGroup.
Data requirements for variables
Variables require data. If the right data isn't available to the variable, then the condition won't work and the workflow fails. Based on which trigger you selected as the start of your workflow, the options for what variables to add to your conditions change to reflect the possible options based on the available data.
For example, if your workflow starts with the Product created trigger, then the conditions that you create from that trigger are limited to the variables available from the product dataset. Therefore, variables such as product.category.name, product.vendor, and variants_item.displayName are all available to use as part of the condition. By contrast, variables such as customer.verifiedEmail or subscriptionContracts_item.status wouldn't display as options, because those aren't associated with the product dataset.
However, this doesn't necessarily mean that data contained in other datasets is completely inaccessible. Some data can be accessed from multiple paths in the API, in the same way that you might click through different links to reach the same page in the Shopify admin. In practice, this means that different triggers require different variable notation to return the same information.
For example, you want your workflow to check the tags on a customer's profile. If your workflow starts with the Order created trigger, then the variable would be order.customer.tags because the workflow starts with the order data, then checks the customer information in the order, then checks the tags on that customer. If your workflow starts with the Customer created trigger, then the variable would simply be customer.tags because the workflow starts with the customer data, so it can go directly to checking the tags on the customer profile.
Check a variable's path when searching based on keywords
Because of the dot notation style in Shopify Flow, searching for variables to use in a condition based on keywords can return multiple results. Understanding what the variable's path is indicating is important when determining which variable to choose when building your condition.
For example, your workflow uses the Order created trigger, and you search for a variable using the keyword tags. Your search could return the following results, which check for different information in the order:
order.tags: The tags applied to the order itself. For example, #rush order or #gift.order.customer.tags: The tags applied to the customer who placed the order. For example, #VIP or #affiliate.order.lineItems.product.tags: The tags applied to the products purchased in the order. For example, #fragile or #requiresID.
Based on which type of tags that you want the workflow to check for, you need to select the correct variable so your condition functions as expected.
Understanding logical operators in conditions
Logical operators define how your condition is applied and result in a statement being either true or false. When a condition reads "If A is greater than 10...", the is greater than part is the logical operator. Choosing a logical operator for a condition is essentially telling the condition how to evaluate the variable.
In Shopify Flow workflows, there are 3 types of logical operators:
- Field-level operators, such as Greater than or Starts with.
- List operators, such as At least one of or All of.
- Condition-level operators, such as AND or OR.
Field-level operators and list operators apply at the variable level, and condition-level operators apply to the overall condition and can be used to combine multiple variables into a single condition.
Field-level operators are the most common types of operator, used in every type of variable statement. With field-level operators, you can create conditional statements such as "If A is greater than 10, then do X" or "If B contains 'VIP', then do X" to have a greater degree of control over which values of a variable return a true result. Equal to is the default logical operator.
List operators can apply only to variables that can return a list of results. For example, the lineItems_item.variant.price variable returns the price for a product variant in the order, which can return a list of results when the customer bought multiple products in the same order. This means that you could apply a list operator such as At least one of when you want a conditional statement such as "lineItems_item.variant.price is greater than $10" to be true when there is at least 1 product variant in the order that's over $10. By contrast, list operators don't display for variables that can return only 1 result at a time. For example, there's only 1 possible value for a variable such as order.createdAt because an order can be created only one time, so list operators aren't displayed as options to modify the statement containing that variable.
Condition-level operators such as AND and OR let you include multiple variables in the same condition. For example, instead of a simple conditional statement such as "If A equals 5, then do X", you can build more complex conditions such as "If A equals 5 and B is greater than 10, then do X" which requires both A and B variables to be true, or "If A equals 5 or B is greater than 10 or C is less than 1, then do X" which requires only 1 of A, B, or C to be true. Use AND when everything in a workflow must be true; use ORwhen any 1 criteria being met is enough for the condition to be true.
Why this matters: Understanding how logical operators work in conditions lets you build workflows that check for exactly the criteria that you want. With the 3 types of logical operators, you can craft detailed and complex conditional statements to create workflows that check for very specific conditions.
Learn more detailed information about logical operators in conditions.