Auto-tag customers when their order is tagged, with Mechanic.

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

Auto-tag customers when their order is tagged

This task watches for order tags, and adds a corresponding tag to the customer whenever a known order tag is found.

Runs Occurs whenever an order is updated. Configuration includes order tags and customer tags.

15-day free trial – unlimited tasks

Documentation

This task watches for order tags, and adds a corresponding tag to the customer whenever a known order tag is found.

Configure this task with order tags on the left, and customer tags on the right. When an order is created or updated with one or more of the tags on the left, the corresponding customer tags will be applied to the customer. Simple as that. :)

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/updated
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
order tags and customer tags (keyval, required)
Code
{% if event.preview %}
  {% capture order_json %}
    {
      "tags": {{ options.order_tags_and_customer_tags__keyval_required.first.first | json }},
      "customer": {
        "admin_graphql_api_id": "gid://shopify/Customer/1234567890",
        "tags": ""
      }
    }
  {% endcapture %}

  {% assign order = order_json | parse_json %}
{% endif %}

{% assign order_tags = order.tags | split: ", " %}
{% assign customer_tags = order.customer.tags | split: ", " %}

{% assign customer_tags_to_apply = array %}

{% for order_tag in order_tags %}
  {% assign customer_tag_to_apply = options.order_tags_and_customer_tags__keyval_required[order_tag] %}
  {% if customer_tag_to_apply != blank %}
    {% if customer_tags contains customer_tag_to_apply %}
      {% log message: "Customer already has this tag; skipping", tag: customer_tag_to_apply %}
    {% else %}
      {% assign customer_tags_to_apply[customer_tags_to_apply.size] = customer_tag_to_apply %}
    {% endif %}
  {% endif %}
{% endfor %}

{% if customer_tags_to_apply != empty %}
  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: {{ order.customer.admin_graphql_api_id | json }}
        tags: {{ customer_tags_to_apply | 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
Order tags and customer tags
{"order-tag-to-watch-for"=>"corresponding-customer-tag-to-apply"}