Auto-tag orders with customer tags when new customer tags are added
Activating this task will automatically keep the order tags up to date with the customer's tags.
Try this taskWhen it runs
Occurs whenever a customer is updated
Documentation
Activating this task will automatically keep the order tags up to date with the customer's tags.
When a customer is updated, this task will go through each of that customer's past orders and add all of the customer's current tags as order tags (if any new tags are found).
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
shopify/customers/update
How task subscriptions work
Task code
{% assign customer_tags = customer.tags | split: ", " %}
{% if event.preview %}
{% action "shopify" %}
mutation {
tagsAdd(
id: "gid://shopify/Order/123456"
tags: ["foo"]
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% else %}
{% for order in customer.orders.any %}
{% assign order_tags = order.tags | split: ", " %}
{% assign tags_to_add = array %}
{% for tag in customer_tags %}
{% unless order_tags contains tag %}
{% assign tags_to_add[tags_to_add.size] = tag %}
{% endunless %}
{% endfor %}
{% if tags_to_add != empty %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ tags_to_add | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% endfor %}
{% endif %}
Mechanic Liquid reference