Auto-tag orders by shipping address city, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

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.

Runs Occurs whenever an order is created. Configuration includes city and tag to apply.

15-day free trial – unlimited tasks

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
shopify/orders/create
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
city (required), tag to apply (required)
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 %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more