Send an email when a purchase is made from a certain collection with Mechanic.

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

Send an email when a purchase is made from a certain collection

by Mechanic Team (team@usemechanic.com)

This task will monitor incoming orders for any products that are included in the collection you choose.

Runs when an order is paid. Configuration includes required collection, email address, email subject, and email body.

15-day free trial – unlimited tasks

Documentation

This task will monitor incoming orders for any products that are included in the collection you choose. Learn where to find the collection ID.

Please note: This task does not determine what collection the customer may have been browsing when they added the product to the cart. This task simply checks to see which collections contain each purchased product, looking for a match with the collection you choose.

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 paid (shopify/orders/paid)
Options
required collection (number, required), email address (required), email subject (required), email body (multiline, required)
Script
{% assign qualifying_line_item_titles = array %}

{% for line_item in order.line_items %}
  {% if line_item.product_id %}
    {% assign line_item_collection_ids = line_item.product.collects | map: "collection_id" %}
    {% if line_item_collection_ids contains options.required_collection_id__number_required %}
      {% assign qualifying_line_item_titles[qualifying_line_item_titles.size] = line_item.title %}
    {% endif %}
  {% endif %}
{% endfor %}

{% if event.preview or qualifying_line_item_titles != empty %}
  {% assign line_item_titles = qualifying_line_item_titles | uniq | join: ", " %}
  {% assign collection_title = shop.collections[options.required_collection_id__number_required].title %}

  {% if event.preview %}
    {% assign line_item_titles = "(products)" %}
    {% assign collection_title = "(collection)" %}
  {% endif %}

  {% action "email" %}
    {
      "to": {{ options.email_address__required | json }},
      "subject": {{ options.email_subject__required | replace: "COLLECTION_TITLE", collection_title | replace: "LINE_ITEM_TITLES", line_item_titles | json }},
      "body": {{ options.email_body__multiline_required | replace: "COLLECTION_TITLE", collection_title | replace: "LINE_ITEM_TITLES", line_item_titles | strip | newline_to_br | json }},
      "from_display_name": {{ shop.name | json }}
    }
  {% endaction %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Email subject
New purchase for LINE_ITEM_TITLES, from COLLECTION_TITLE
Email body
Hello,

Order {{ order.name }} includes LINE_ITEM_TITLES, from COLLECTION_TITLE.

<a href="https://{{ shop.domain }}/admin/orders/{{ order.id }}">Manage this order in Shopify</a>

Thanks,
-Mechanic, for {{ shop.name }}