Auto-tag orders by shipping address city
This task automatically tags orders based on the city in the shipping address. Within this key you define the city and the tag on the order.
Try this taskWhen it runs
Occurs whenever an order is created
What you choose
- City
- Tag to apply
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
- City (required)
- Tag to apply (required)
Task code
{% if event.preview %}
{% assign order = '{"admin_graphql_api_id": "gid://shopify/Order/1234567890"}' | parse_json %}
{% assign order['shipping_address'] = hash %}
{% assign order['shipping_address']['city'] = options.city__required %}
{% endif %}
{% assign order_address_city_downcased = order.shipping_address.city | downcase %}
{% assign required_city_downcased = options.city__required | downcase %}
{% if order_address_city_downcased == required_city_downcased %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ options.tag_to_apply__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
Mechanic Liquid reference