Email customers when their order is tagged, with Mechanic.

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

Email customers when their order is tagged

Improve your customer relationships without complicated your workflow - use this task to send automatic emails whenever your staff adds a certain tag to an order. (Mechanic will add another tag to your order when the email is sent, for visibility.)

Runs Occurs whenever an order is updated. Configuration includes tag to watch for, email subject, email body, ignore orders older than this task, and ignore orders having this tag.

15-day free trial – unlimited tasks

Documentation

Improve your customer relationships without complicated your workflow - use this task to send automatic emails whenever your staff adds a certain tag to an order. (Mechanic will add another tag to your order when the email is sent, for visibility.)

This task monitors incoming orders, and updates to existing orders, looking for the tag of your choice. When the tag is detected, this task will send an email to the address on file for that order.

Important notes

  • This task also adds a second tag to the order when the email is sent, as a flag to mark the order as having had that email sent. This helps Mechanic remember what orders should not have an email sent.
  • This second tag defaults to a concatenation of the tag to watch for and "-email-sent"; however, because Shopify has a 40 character limit on order tags, the tag to watch for will be truncated to the first 29 characters if needed to form the concatenated tag. This truncation will only affect the email sent tag, not the original tag being watched for.
  • Use the "Ignore orders older than this task" option to avoid a flood of unexpected email, instructing Mechanic to ignore any existing or new tags on older orders.

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
tag to watch for (required), email subject (required), email body (required, multiline), ignore orders older than this task (boolean), ignore orders having this tag
Code
{% comment %}
  Establish option order:

  {{ options.tag_to_watch_for__required }}
  {{ options.email_subject__required }}
  {{ options.email_body__required_multiline }}
  {{ options.ignore_orders_older_than_this_task__boolean }}
  {{ options.ignore_orders_having_this_tag }}
{% endcomment %}

{% if event.preview %}
  {% capture order_json %}
    {
      "admin_graphql_api_id": "gid://shopify/Order/1234568790",
      "email": "customer@example.com",
      "tags": {{ options.tag_to_watch_for__required | json }},
      "created_at": "2000-01-01"
    }
  {% endcapture %}

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

{% capture email_sent_tag %}{{ options.tag_to_watch_for__required | slice: 0, 29 }}-email-sent{% endcapture %}
{% assign order_tags = order.tags | split: ", " %}

{% assign order_qualifies = true %}

{% unless order_tags contains options.tag_to_watch_for__required %}
  {% assign order_qualifies = false %}
  {% log message: "The order does not have the required tag", order_tags: order_tags, required_tag: options.tag_to_watch_for__required %}
{% else %}
  {% if order_tags contains email_sent_tag %}
    {% assign order_qualifies = false %}
    {% log message: "Judging by the order's tags, this order appears to have already had its email sent", order_tags: order_tags, required_tag: options.tag_to_watch_for__required, email_sent_tag: email_sent_tag %}
  {% elsif options.ignore_orders_having_this_tag != blank and order_tags contains options.ignore_orders_having_this_tag %}
    {% assign order_qualifies = false %}
    {% log message: "This order has the required tag, but it *also* has the tag we're meant to ignore", order_tags: order_tags, required_tag: options.tag_to_watch_for__required, ignore_tag: options.ignore_orders_having_this_tag %}
  {% endif %}
{% endunless %}

{% if order_qualifies and options.ignore_orders_older_than_this_task__boolean %}
  {% assign order_created_at = order.created_at | date: "%s" %}
  {% assign task_created_at = task.created_at | date: "%s" %}
  {% if order_created_at < task_created_at %}
    {% assign order_qualifies = false %}
    {% log message: "'Ignore orders older than this task' is enabled, and this order is indeed older than the task", order_created_at: order_created_at, task_created_at: task_created_at %}
  {% endif %}
{% endif %}

{% if order_qualifies %}
  {% action "email" %}
    {
      "to": {{ order.email | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ options.email_body__required_multiline | strip | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }}
    }
  {% endaction %}

  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: {{ order.admin_graphql_api_id | json }}
        tags: {{ email_sent_tag | 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
Tag to watch for
in-production
Email subject
Order {{ order.name }} is in production
Email body
Hi {{ order.customer.first_name | default: "there" }},

Your order is in the shop! We'll be in touch when it's been shipped.

Thanks,
The team at {{ shop.name }}
Ignore orders older than this task
true