Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
At my company, we want to tag customers with a tag called "Premium" based on if they have had 3+ orders of tag "Recurring Order" in last 90 days. When I use the flow, I have the following set up in mind:
Trigger "Order is Created" >> Get Order Data (Query that filters for customer of the original order, within last 90 days, and filters orders ONLY with "Recurring Order" tag) >> Count >> Conditional "if count >=3" >> Tag customer
The part I cannot figure out is the Liquid code to create the part of the query to filter for orders with a specific tag. I tried the following
----------------------------
customer_id:{{order.customer.legacyResourceId}} AND created_at:>='{{ "now" | date_minus:"90 day" }}' AND
order.tags contains 'Recurring Order'
-------------------------------
However, it would not fire correctly, and my thought is because, when I look at the liquid documentation, the order.tags is stored as an array, not a string. Furthermore, when I go to templates, order.tags is always used in a for loop, such as
{% for tags_item in order.tags %}
{{tags_item}}
{% endfor %}
How could I use this for loop within a logic statement to check if ONLY one tag is equal to my 'Recurring Order' tag?
Or would it be possible to change order.tags into a string somehow? Like '{{order.tags}}' and use a "contains" condition?
This is my first time using liquid, so any help would be greatly, greatly appreciated!
Solved! Go to the solution
This is an accepted solution.
There are a couple of things going on here. While that field *is* a liquid string, what you are actually trying to generate from that liquid is (as mentioned in the task) a valid Shopify Query Search Syntax string. So the text that you write in the box will be parsed by liquid to replace everything inside `{{ }}` with the actual value, but then that generated text is something you want to be in the query search syntax (which is more or less entirely unrelated to liquid).
If we look at the query parameter on the graphql `orders` search (which is what Flow ultimately uses), we can see that `tag` is a supported field. So, using a `Field search` from the Shopify Query Search Syntax (which is what you have already used for `customer_id` and `created_at`), you should be able to just add `tag:'Recurring Order'` to your query to get what you want.
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
There are a couple of things going on here. While that field *is* a liquid string, what you are actually trying to generate from that liquid is (as mentioned in the task) a valid Shopify Query Search Syntax string. So the text that you write in the box will be parsed by liquid to replace everything inside `{{ }}` with the actual value, but then that generated text is something you want to be in the query search syntax (which is more or less entirely unrelated to liquid).
If we look at the query parameter on the graphql `orders` search (which is what Flow ultimately uses), we can see that `tag` is a supported field. So, using a `Field search` from the Shopify Query Search Syntax (which is what you have already used for `customer_id` and `created_at`), you should be able to just add `tag:'Recurring Order'` to your query to get what you want.
To learn more visit the Shopify Help Center or the Community Blog.
Oh that's amazing, thank you for these clarifications! So just to be clear, even if the order has multiple tags, tag:'Recurring Order' will be considered True if any of the many tags the customer has are equal to 'Recurring Order'?
Yes, that is my understanding of the field.
To learn more visit the Shopify Help Center or the Community Blog.
Tags can be parsed as an array, and Liquid can parse it. So with "contains" in Liquid, you have quite a solution.
Usually product, or order tags can overwrite themselves. But given the unique ID of each order, this is not an issue. It depends the context of where you ask for several services or Id of Shopify 😉
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024