Send an email when a specific product is shipped, with Mechanic.

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

Send an email when a specific product is shipped

Use this task to notify customers about product-specific information, that should only be delivered when a successful fulfillment is registered for their purchased product.

Runs Occurs whenever a fulfillment is created and Occurs whenever a fulfillment is updated. Configuration includes required product id, email subject, and email body.

15-day free trial – unlimited tasks

Documentation

Use this task to notify customers about product-specific information, that should only be delivered when a successful fulfillment is registered for their purchased product.

This task requires a product ID. Learn where to find this.

YouTube: Watch the development video!

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/fulfillments/create
shopify/fulfillments/update
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
required product id (number, required), email subject (required), email body (multiline, required)
Code
{% assign metafield_key = fulfillment.id | append: options.required_product_id__number_required | append: task.id | sha256 | slice: 0, 30 %}

{% if event.preview %}
  {% assign fulfillment = hash %}
  {% assign fulfillment["id"] = 1234567890 %}
  {% assign fulfillment["status"] = "success" %}
  {% assign fulfillment["order"] = hash %}
  {% assign fulfillment["order"]["email"] = "customer@example.com" %}
  {% assign fulfillment["order"]["metafields"] = hash %}
  {% assign fulfillment["order"]["metafields"]["mechanic"] = hash %}
  {% assign fulfillment["order"]["metafields"]["mechanic"][metafield_key] = nil %}
  {% assign fulfillment["line_items"] = array %}
  {% assign fulfillment["line_items"][0] = hash %}
  {% assign fulfillment["line_items"][0]["product_id"] = options.required_product_id__number_required %}
{% endif %}

{% assign fulfillment_qualifies = false %}

{% if fulfillment.status != "success" %}
  {% log message: "This task only sends emails for successful fulfillments.", fulfillment_status: fulfillment.status %}
{% else %}
  {% assign fulfillment_product_ids = fulfillment.line_items | map: "product_id" %}
  {% unless fulfillment_product_ids contains options.required_product_id__number_required %}
    {% log message: "This fulfillment does not contain the configured product.", required_product_id: options.required_product_id__number_required %}
  {% else %}
    {% if fulfillment.order.email != blank %}
      {% if fulfillment.order.metafields.mechanic[metafield_key] %}
        {% log "This task already sent an email for this fulfillment and product." %}
      {% else %}
        {% assign fulfillment_qualifies = true %}
      {% endif %}
    {% endif %}
  {% endunless %}
{% endif %}

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

  {% action "shopify" %}
    [
      "update",
      [
        "order",
        {{ fulfillment.order_id | json }}
      ],
      {
        "metafields": [
          {
            "namespace": "mechanic",
            "key": {{ metafield_key | json }},
            "type": "number_integer",
            "value": "1",
            "description": {{ "Mechanic sent an email for this fulfillment, for product " | append: options.required_product_id__number_required | append: ", in task " | append: task.id | json }}
          }
        ]
      }
    ]
  {% endaction %}
{% endif  %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Email subject
Order {{ fulfillment.order.name | default: "#1234" }}: Your product has been shipped!
Email body
Hello,

Thanks for your order!

Cheers,
{{ shop.name }}