Auto-tag new orders using the customer's tags
Use this task to apply the same categorizations you use for your customers. Useful for pre-approving customers, and then quickly sorting your orders based on that pre-approval. Optionally, configure this task to only copy certain tags from customers to their orders.
Try this taskWhen it runs
Occurs whenever an order is created
What you choose
Only copy these tags
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
- Only copy these tags (array)
Task code
{% if event.preview %}
{% capture order_json %}
{
"admin_graphql_api_id": "gid://shopify/Order/1234567890",
"tags": "",
"customer": {
"tags": {{ options.only_copy_these_tags__array | join: ", " | default: "wholesale, approved" | json }}
}
}
{% endcapture %}
{% assign order = order_json | parse_json %}
{% endif %}
{% assign customer_tags = order.customer.tags | split: ", " %}
{% assign order_tags = order.tags | split: ", " %}
{% assign tags_to_add = array %}
{% for tag in customer_tags %}
{% if options.only_copy_these_tags__array == blank or options.only_copy_these_tags__array contains tag %}
{% unless order_tags contains tag %}
{% assign tags_to_add[tags_to_add.size] = tag %}
{% endunless %}
{% 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