[ { "label": "Notify if a customer has more than two pending orders", "trigger_type": [ "order_created" ], "object_type": "order", "app_id": "triggers", "settings": { "priority": 0, "condition_groups": { "1": { "conditions": { "1": { "field": "order.customer.orders_count", "settings": { "operator": "gt", "value": "2", "token_object_type": "order", "condition_type": "AND" }, "weight": 999 } }, "actions": { "1": { "type": "custom", "settings": { "token_object_type": "order", "label": "Check if customer has more than 2 pending orders. ", "twig": "{# load the customers pending orders #}\r\n{% set orders = RUN_ACTION('shopify_api_request',{\r\n method: \"GET\",\r\n path: \"customers\/\"~order.customer.id~\"\/orders\",\r\n data: {financial_status:\"pending\"},\r\n format: \"order\"\r\n})%}\r\n{# check if the number of pending orders returned is more than two #}\r\n{% if orders.response|length > 2 %}\r\n{% set title = \"Customomer:\"~ order.customer.display_name~\" has \"~orders.response|length~\" pending orders\" %}\r\n{% set message = \"Pending orders notification\" %}\r\n{% set res = QUEUE_ACTION('email',{\r\nto: shop.email,\r\n subject: title,\r\n body: message,\r\n plain_text: false\r\n})%}\r\n{% endif %}", "wait": "0", "cw_timezone": "America\/Chicago", "custom_wait": "" }, "weight": 999, "target_key": "order" } } } }, "shared_workflow_id": 39998 }, "description": "This automation will send an email if a customer with two or more unpaid orders raised another order" } ]