Email someone when a certain product is purchased
This task sends an email notification, immediately after an order is paid - if a product in the order has a title matching the product title you configure. Optionally, configure this task with a delay, in days, to wait before sending the email. (The task will not send any emails for orders that have since been cancelled.)
Try this taskWhen it runs
Occurs whenever an order is paid
What you choose
- Product title
- Email address
- Email subject
Show 3 more
- Email body
- Reply to email address
- Number of days to wait before emailing
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
{% assign delay_days = options.number_of_days_to_wait_before_emailing__number %}
shopify/orders/paid{% if delay_days != blank %}+{{ delay_days }}.days{% endif %}
How task subscriptions work
Option types and flags
- Product title (required)
- Email address (required)
- Email subject (required)
- Email body (multiline, required)
- Number of days to wait before emailing (number)
Task code
{% assign product_title = options.product_title__required %}
{% assign email_address = options.email_address__required %}
{% assign email_subject = options.email_subject__required %}
{% assign email_body = options.email_body__multiline_required %}
{% assign reply_to_email_address = options.reply_to_email_address %}
{% comment %}
-- requery the order in case a delay is configured in the task
{% endcomment %}
{% capture query %}
query {
order(id: {{ order.admin_graphql_api_id | json }}) {
id
cancelledAt
lineItems(first: 250) {
nodes {
title
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"order": {
"id": "gid://shopify/Order/1234567890",
"lineItems": {
"nodes": [
{
"title": {{ product_title | json }}
}
]
}
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% assign order = result.data.order %}
{% comment %}
-- don't send notification email if the order has been cancelled
{% endcomment %}
{% if order.cancelledAt != blank %}
{% break %}
{% endif %}
{% comment %}
-- send notification email if any line item contains the configured product title
{% endcomment %}
{% for line_item in order.lineItems.nodes %}
{% if line_item.title == product_title %}
{% action "email" %}
{
"to": {{ email_address | json }},
"subject": {{ email_subject | json }},
"body": {{ email_body | strip | newline_to_br | json }},
"reply_to": {{ reply_to_email_address | default: shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% break %}
{% endif %}
{% endfor %}
Mechanic Liquid reference