Auto-add a note for new orders having a certain tag, with Mechanic.

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

Auto-add a note for new orders having a certain tag

This task monitors newly-created orders, and appends an order note if that order was created with a certain tag.

Runs Occurs whenever an order is created. Configuration includes required order tag and order note to add.

15-day free trial – unlimited tasks

Documentation

This task monitors newly-created orders, and appends an order note if that order was created with a certain tag.

Note: this task does not monitor order updates, and so tags added later will not add an order note.

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
required order tag (required) , order note to add (required, multiline)
Code
{% assign required_tag_downcased = options.required_order_tag__required | downcase %}

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

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

{% assign tags_downcased = order.tags | downcase | split: ", " %}

{% if tags_downcased contains required_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 %}
{% else %}
  {% log order_tags: order.tags %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Required order tag
foo
Order note to add
bar