Auto-tag new orders using the customer's tags, with Mechanic.

Mechanic is a development platform for Shopify. :)

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.

Runs when an order is created. Configuration includes only copy these tags.

15-day free trial – unlimited tasks

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, 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.

Open source
View on GitHub to contribute to this task
Events
when an order is created (shopify/orders/create)
Options
only copy these tags (array)
Script
{% 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 tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.