Email customers when their order is tagged with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Email customers when their order is tagged

by Isaac Bowen (team@usemechanic.com)

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 when an order is created and when an order is updated. Configuration includes tag to watch for, email subject, email body, and email template html.

15-day free trial – unlimited tasks

Documentation

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.

To use a rich email template, with HTML and CSS, set up your template with the text EMAIL_BODY where you'd like Mechanic to fill in the text of your email message. Then, paste all the code for your template into the "Email template HTML" task option.

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.
  • To help out merchants who have lots of existing orders, this task doesn't watch orders that were created before you add this task to your Mechanic account.

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)
when an order is updated (shopify/orders/updated)
Options
tag to watch for (required), email subject (required), email body (required, multiline), email template html (code, multiline)
Script
{% assign tag_to_watch_for = options.tag_to_watch_for__required %}
{% capture email_sent_tag %}{{ tag_to_watch_for }}-email-sent{% endcapture %}
{% assign order_tags = order.tags | split: ", " %}

{% assign order_qualifies = false %}
{% assign order_created_at = order.created_at | date: "%s" %}
{% assign task_created_at = task.created_at | date: "%s" %}
{% if order_tags contains tag_to_watch_for and order_created_at >= task_created_at %}
  {% unless order_tags contains email_sent_tag %}
    {% assign order_qualifies = true %}
  {% endunless %}
{% endif %}

{% assign email_subject = options.email_subject__required %}
{% assign email_body = options.email_body__required_multiline | strip | newline_to_br %}

{% assign email_template = options.email_template_html__code_multiline %}
{% if email_template == blank %}
  {% assign email_template = "EMAIL_BODY" %}
{% endif %}

{% assign email_html = email_template | replace: "EMAIL_BODY", email_body %}

{% if event.preview or order_qualifies %}
  {
    "action": {
      "type": "email",
      "options": {
        "to": {{ order.email | json }},
        "subject": {{ email_subject | json }},
        "body": {{ email_html | json }},
        "reply_to": {{ shop.customer_email | json }},
        "from_display_name": {{ shop.name | json }}
      }
    }
  }

  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "order",
          {{ order.id | json }}
        ],
        {
          "tags": {{ order.tags | add_tag: email_sent_tag | json }}
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
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 }}