Auto-add an order note for customers having a certain tag, with Mechanic.

Mechanic is a development platform for Shopify. :)

Auto-add an order note for customers having a certain tag

This task monitors newly-created orders, and appends an order note if the customer has a certain tag. Useful for identifying orders for a particular customer group, and adding fulfillment notes as appropriate.

Runs when an order is created. Configuration includes required customer tag and order note to add.

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
required customer tag (required), order note to add (required, multiline)
Script
{% assign required_customer_tag_downcased = options.required_customer_tag__required | downcase %}

{% if event.preview %}
  {% capture order_json %}
    {
      "note": "An existing order note",
      "name": "#9999",
      "admin_graphql_api_id": "gid:\/\/shopify\/Order\/1234567890",
      "customer": {
        "tags": {{ options.required_customer_tag__required | json }}
      }
    }
  {% endcapture %}

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

{% assign customer_tags_downcased = order.customer.tags | downcase | split: ", " %}
{% if customer_tags_downcased contains required_customer_tag_downcased %}
  {% assign note = order.note | append: newline | append: newline | append: options.order_note_to_add__required_multiline | strip %}

  {% action "shopify" %}
    mutation {
      orderUpdate(
        input: {
          id: {{ order.admin_graphql_api_id | json }}
          note: {{ note | 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.