Auto-tag orders based on customer account tags
Use this task to apply certain tags to newly-created orders, based on what tags are on the associated customer. Configure this task with one-to-one mappings of customer tags to look for, connected to order tags to add.
Try this taskWhen it runs
Occurs whenever an order is created
What you choose
Customer tags to look for and order tags to add
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/create
How task subscriptions work
Option types and flags
- Customer tags to look for and order tags to add (keyval)
Task code
{% if event.preview %}
{% assign order = hash %}
{% assign order["admin_graphql_api_id"] = "gid://shopify/Order/123456780" %}
{% assign order["customer"] = hash %}
{% assign order["customer"]["tags"] = options.customer_tags_to_look_for_and_order_tags_to_add__keyval.first.first %}
{% endif %}
{% assign customer_tags = order.customer.tags | split: ", " %}
{% assign tags_to_add = array %}
{% assign tag_pairs = options.customer_tags_to_look_for_and_order_tags_to_add__keyval %}
{% for pair in tag_pairs %}
{% if customer_tags contains pair.first %}
{% assign tags_to_add = tags_to_add | add_tag: pair.last %}
{% endif %}
{% 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 %}
Mechanic Liquid reference
Default option values
- Customer tags to look for and order tags to add
{"wholesale-customer" => "wholesale-order"}