Auto-tag customers when their order is tagged
This task watches for order tags, and adds a corresponding tag to the customer whenever a known order tag is found.
Try this taskWhen it runs
Occurs whenever an order is updated
What you choose
Order tags and customer tags
Documentation
This task watches for order tags, and adds a corresponding tag to the customer whenever a known order tag is found.
Configure this task with order tags on the left, and customer tags on the right. When an order is created or updated with one or more of the tags on the left, the corresponding customer tags will be applied to the customer. Simple as that. :)
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/orders/updated
How task subscriptions work
Option types and flags
- Order tags and customer tags (keyval, required)
Task code
{% if event.preview %}
{% capture order_json %}
{
"tags": {{ options.order_tags_and_customer_tags__keyval_required.first.first | json }},
"customer": {
"admin_graphql_api_id": "gid://shopify/Customer/1234567890",
"tags": ""
}
}
{% endcapture %}
{% assign order = order_json | parse_json %}
{% endif %}
{% assign order_tags = order.tags | split: ", " %}
{% assign customer_tags = order.customer.tags | split: ", " %}
{% assign customer_tags_to_apply = array %}
{% for order_tag in order_tags %}
{% assign customer_tag_to_apply = options.order_tags_and_customer_tags__keyval_required[order_tag] %}
{% if customer_tag_to_apply != blank %}
{% if customer_tags contains customer_tag_to_apply %}
{% log message: "Customer already has this tag; skipping", tag: customer_tag_to_apply %}
{% else %}
{% assign customer_tags_to_apply[customer_tags_to_apply.size] = customer_tag_to_apply %}
{% endif %}
{% endif %}
{% endfor %}
{% if customer_tags_to_apply != empty %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.customer.admin_graphql_api_id | json }}
tags: {{ customer_tags_to_apply | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
Mechanic Liquid reference
Default option values
- Order tags and customer tags
{"order-tag-to-watch-for" => "corresponding-customer-tag-to-apply"}