We have examples in repo here: https://github.com/Shopify/flow-code-examples/tree/main/run-code-examples
Topic summary
A merchant wants to create a Shopify Flow workflow that triggers when a customer places their 2nd or 3rd order, comparing the order value against their previous order. The goal is to identify when a second order falls below a threshold (e.g., $728) after a first order exceeded it, enabling targeted follow-up promotions.
Key Challenge:
The user struggled with using the “Get order data” action to retrieve and compare the last two orders’ subtotals.
Solution Provided:
- Sort orders by “Created at” in descending order to get the most recent orders first
- Use query filter “Placed by same customer in last day” (removing the date constraint)
- Since Flow conditions cannot directly compare two list items, use the “Run code” action
- The code checks if customer has 2+ orders, parses subtotals of current and previous orders, then returns a boolean “followUp” value
- A subsequent condition step checks if followUp is true to trigger actions
Important Note:
The Customer.numberOfOrders property has a 1-2 hour delay in updating, so that check was removed from the workflow.
Outcome:
Complete working code examples were provided for both scenarios: any order after the first, and specifically for 2nd/3rd orders only.