Auto-tag new orders with a value from the customer note, with Mechanic.

Mechanic is a development platform for Shopify. :)

Auto-tag new orders with a value from the customer note

by Isaac Bowen (team@usemechanic.com)

This task watches incoming orders, and tags each order with a certain value from the customer's note, as identified by a configurable prefix. For example, if your customers have notes resembling "Username: xyz", configure this task with the prefix "Username: " to have it tag incoming orders as "xyz". Useful with apps like inkFrog, which add eBay usernames to customer notes, using a prefix.

Runs when an order is created. Configuration includes tag prefix in customer note.

15-day free trial – unlimited tasks

Documentation

This task watches incoming orders, and tags each order with a certain value from the customer's note, as identified by a configurable prefix. For example, if your customers have notes resembling "Username: xyz", configure this task with the prefix "Username: " to have it tag incoming orders as "xyz".

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.

Events
when an order is created (shopify/orders/create)
Options
tag prefix in customer note (required)
Script
{% if event.preview %}
  {% capture order_json %}
    {
      "admin_graphql_api_id": "gid://shopify/Order/12345",
      "customer": {
        "note": {{ options.tag_prefix_in_customer_note__required | append: "abc123" | json }}
      }
    }
  {% endcapture %}

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

{% assign note_lines = order.customer.note | split: newline %}
{% assign desired_prefix = options.tag_prefix_in_customer_note__required %}
{% assign tag = nil %}

{% for line in note_lines %}
  {% assign line_prefix = line | slice: 0, desired_prefix.size %}
  {% if line_prefix == desired_prefix %}
    {% assign tag = line | replace: line_prefix, "" %}
  {% endif %}
{% endfor %}

{% if tag != blank %}
  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: {{ order.admin_graphql_api_id | json }}
        tags: {{ tag | json }}
      ) {
        node {
          ... on Order {
            tags
          }
        }
        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.
Defaults
Tag prefix in customer note
eBay User: