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

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

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

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 Occurs whenever 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". Useful with apps like inkFrog, which add eBay usernames to customer notes, using a prefix.

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, 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
tag prefix in customer note (required)
Code
{% 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 %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Tag prefix in customer note
eBay User: