Send a new-order email to someone based on a cart attribute, with Mechanic.

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

Send a new-order email to someone based on a cart attribute

This task sends a new-order email alert to somebody specific, based on the contents of a cart attribute. Useful for allowing customers to select their salesperson, alerting the appropriate salesperson when the order is placed.

Runs Occurs whenever an order is created. Configuration includes cart attribute name, cart attribute values and email addresses, email subject, email body, and only send for paid orders.

15-day free trial – unlimited tasks

Documentation

This task sends a new-order email alert to somebody specific, based on the contents of a cart attribute. Useful for allowing customers to select their salesperson, alerting the appropriate salesperson when the order is placed.

This task sends a new-order email alert to somebody specific, based on the contents of a cart attribute. If a matching email address is not found in the task's configuration, no email will be sent.

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
{% if options.only_send_for_paid_orders__boolean %}
  shopify/orders/paid
{% else %}
  shopify/orders/create
{% endif %}
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
cart attribute name (required), cart attribute values and email addresses (keyval, email, required), email subject (required), email body (multiline, required), only send for paid orders (boolean)
Code
{% if event.preview %}
  {% assign order = order | json | parse_json %}
  {% assign order["note_attributes"][0] = hash %}
  {% assign order["note_attributes"][0]["name"] = options.cart_attribute_name__required %}
  {% assign order["note_attributes"][0]["value"] = options.cart_attribute_values_and_email_addresses__keyval_email_required.first.first %}
{% endif %}

{% assign attribute = order.note_attributes | where: "name", options.cart_attribute_name__required | first %}
{% assign attribute_value = attribute.value %}
{% assign email = options.cart_attribute_values_and_email_addresses__keyval_email_required[attribute_value] %}

{% if attribute == nil %}
  {"log": {{ options.cart_attribute_name__required | json | prepend: "This order did not contain the attribute " |  json }}}
{% elsif email == blank %}
  {"log": {{ attribute_value | json | prepend: "There is no configured email corresponding with " |  json }}}
{% else %}
  {% action "email" %}
    {
      "to": {{ 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 %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Cart attribute name
Salesperson
Cart attribute values and email addresses
{"Jenny "=>"jenny@example.com", "Zhang Wei"=>"zhangwei@example.com"}
Email subject
You've got an order! {{ order.name }}
Email body
Hello,

An order has arrived, and it's assigned to you.

https://{{ shop.domain }}/admin/orders/{{ order.id }}

Thanks,
{{ shop.name }}