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.
Try this taskWhen it runs
Occurs whenever an order is created
What you choose
- Cart attribute name
- Cart attribute values and email addresses
- Email subject
- Email body
- Only send for paid orders
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.
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
{% if options.only_send_for_paid_orders__boolean %}
shopify/orders/paid
{% else %}
shopify/orders/create
{% endif %}
How task subscriptions work
Option types and flags
- 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)
Task 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 %}
Mechanic Liquid reference
Default option values
- 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 }}- Only send for paid orders
false