Send your customers reorder reminders, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Send your customers reorder reminders

by Isaac Bowen (team@usemechanic.com)

Useful for customers who need recurring reminders to reorder. Optionally filtering by a customer tag, this task monitors the most recent order for each customer, and sends them reminders every x days since that order.

Runs every day at midnight and when a bulk operation finishes. Configuration includes only include customers having this tag, number of days to wait between emails, email subject, email body, and test mode.

15-day free trial – unlimited tasks

Documentation

This task runs daily, at midnight in your store's timezone. Optionally filtering by a customer tag, it monitors the most recent order for each customer, and sends them reminders every x days since that order. The task will continue sending reorder reminders, every x days since each customer's latest order.

This task will send emails to the address on file for the customer, falling back to the email on file for the order if the customer has no email address.

To test this task, enable test mode, and save. You'll find a new "Run task" button, which will report the emails that would be sent on the current date.

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
every day at midnight (mechanic/scheduler/daily)
when a bulk operation finishes (mechanic/shopify/bulk_operation)
Options
only include customers having this tag, number of days to wait between emails (number, required), email subject (required), email body (multiline, required), test mode (boolean)
Script
{% if event.topic contains "mechanic/scheduler/" or event.topic == "mechanic/user/trigger" %}
  {% assign query = "orders_count:>0" %}
  {% if options.only_include_customers_having_this_tag != blank %}
    {% assign query = options.only_include_customers_having_this_tag | json | prepend: "tag:" | append: " " | append: query %}
  {% endif %}

  {% capture bulk_operation_query %}
    query {
      customers(
        query: {{ query | json }}
      ) {
        edges {
          node {
            email
            lastOrder {
              email
              name
              processedAt
            }
          }
        }
      }
    }
  {% endcapture %}

  {% action "shopify" %}
    mutation {
      bulkOperationRunQuery(
        query: {{ bulk_operation_query | json }}
      ) {
        bulkOperation {
          id
          status
        }
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% elsif event.topic == "mechanic/shopify/bulk_operation" %}
  {% assign now_s = "now" | date: "%s" | times: 1 %}
  {% assign interval_d = options.number_of_days_to_wait_between_emails__number_required %}

  {% if event.preview %}
    {% capture object_json %}
      {
        "email": "customer@example.com",
        "lastOrder": {
          "email": "customer+fallback@example.com",
          "name": "#1234",
          "processedAt": {{ interval_d | times: 24 | times: 60 | times: 60 | times: -1 | plus: now_s | date: "%FT%T%:z" | json }}
        }
      }
    {% endcapture %}

    {% assign bulkOperation = hash %}
    {% assign bulkOperation["objects"] = array %}
    {% assign bulkOperation["objects"][0] = object_json | parse_json %}
  {% endif %}

  {% for customer in bulkOperation.objects %}
    {% if customer.lastOrder == nil %}
      {% continue %}
    {% endif %}

    {% assign processed_at_s = customer.lastOrder.processedAt | date: "%s" | times: 1 %}
    {% assign age_d = now_s | minus: processed_at_s | divided_by: 60 | divided_by: 60 | divided_by: 24 | round %}
    {% assign age_d_modulo = age_d | modulo: interval_d %}

    {% if age_d == 0 %}
      {% continue %}
    {% elsif age_d_modulo != 0 %}
      {% capture message -%}
        Order {{ customer.lastOrder.name }} ({{ customer.email | default: customer.lastOrder.email }}) was placed on {{ customer.lastOrder.processedAt }}. Next email is due in {{ interval_d | minus: age_d_modulo }} day(s).
      {%- endcapture %}
      {% log message %}
      {% continue %}
    {% else %}
      {% assign email_options = hash %}
      {% assign email_options["to"] = customer.email | default: customer.lastOrder.email %}
      {% assign email_options["subject"] = options.email_subject__required | replace: "ORDER_NUMBER", customer.lastOrder.name %}
      {% assign email_options["body"] = options.email_body__multiline_required | replace: "ORDER_NUMBER", customer.lastOrder.name | strip | newline_to_br %}
      {% assign email_options["reply_to"] = shop.customer_email %}
      {% assign email_options["from_display_name"] = shop.name %}

      {% if options.test_mode__boolean %}
        {% action "echo" email_options %}
      {% else %}
        {% action "email" email_options %}
      {% endif %}
    {% endif %}
  {% endfor %}
{% 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
It's time to reorder!
Email body
Hello,

It's been X days since your last order (ORDER_NUMBER). <a href="https://{{ shop.domain  }}/">Return to our store</a>

Thanks,
{{ shop.name }}