Auto-tag orders based on customer account tags, with Mechanic.

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

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.

Runs Occurs whenever an order is created. Configuration includes customer tags to look for and order tags to add.

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
customer tags to look for and order tags to add (keyval)
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 %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Customer tags to look for and order tags to add
{"wholesale-customer"=>"wholesale-order"}