Auto-invite customers after an order, with Mechanic.

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

Auto-invite customers after an order

Automatically prompt customers to activate their customer accounts, after placing an order in your store, by triggering a customizable Shopify-powered email. Useful if your online store unlocks special offers, functionality, or content after making a purchase. Optionally, only send invitations if the customer has ordered a product with a specific tag.

Runs Occurs whenever an order is created. Configuration includes only invite if the customer has not yet been invited, only invite if the customer has this tag, only invite if the order contains a product with this tag, custom invitation email subject, custom invitation email message, and invitation email bcc.

15-day free trial – unlimited tasks

Documentation

Automatically prompt customers to activate their customer accounts, after placing an order in your store, by triggering a customizable Shopify-powered email. Useful if your online store unlocks special offers, functionality, or content after making a purchase. Optionally, only send invitations if the customer has ordered a product with a specific tag.

This task works by asking Shopify to send along an invitation email, using the subject and body that you configure here. The email will use your Shopify account's "Customer account invite" email template, available in the "Notifications" area of your Shopify settings. Note: Because this task triggers a Shopify-powered email, and because this email already uses a Shopify template, the actual message body is optional. (If provided, HTML and CSS are not supported.) And, there's no need to add in an invitation link yourself – this will be taken care of by the Shopify email template as well.

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
shopify/orders/create
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
only invite if the customer has not yet been invited (boolean), only invite if the customer has this tag, only invite if the order contains a product with this tag, custom invitation email subject, custom invitation email message (multiline), invitation email bcc (array)
Code
{% comment %}
  Establish option order:
  {{ options.only_invite_if_the_customer_has_not_yet_been_invited__boolean }}
  {{ options.only_invite_if_the_customer_has_this_tag }}
  {{ options.only_invite_if_the_order_contains_a_product_with_this_tag }}
  {{ options.custom_invitation_email_subject }}
  {{ options.custom_invitation_email_message__multiline }}
  {{ options.invitation_email_bcc__array }}
{% endcomment %}

{% if event.preview %}
  {% assign order = hash %}
  {% assign order["customer"] = hash %}
  {% assign order["customer"]["state"] = "disabled" %}

  {% if options.only_invite_if_the_customer_has_this_tag != blank %}
    {% assign order["customer"]["tags"] = options.only_invite_if_the_customer_has_this_tag %}
  {% endif %}

  {% if options.only_invite_if_the_order_contains_a_product_with_this_tag != blank %}
    {% capture line_items_json %}
      [
        {
          "product": {
            "tags": {{ options.only_invite_if_the_order_contains_a_product_with_this_tag | json }}
          }
        }
      ]
    {% endcapture %}
    {% assign order["line_items"] = line_items_json | parse_json %}
  {% endif %}
{% endif %}

{% assign customer_qualifies = true %}
{% if order.customer == nil or order.customer.state == "enabled" %}
  {% assign customer_qualifies = false %}
{% elsif options.only_invite_if_the_customer_has_not_yet_been_invited__boolean and order.customer.state == "invited" %}
  {% assign customer_qualifies = false %}
{% elsif options.only_invite_if_the_customer_has_this_tag != blank %}
  {% assign customer_tags = order.customer.tags | downcase | split: ", " %}
  {% assign tag_to_match = options.only_invite_if_the_customer_has_this_tag | strip | downcase %}
  {% unless customer_tags contains tag_to_match %}
    {% assign customer_qualifies = false %}
  {% endunless %}
{% endif %}

{% assign order_qualifies = false %}
{% if customer_qualifies %}
  {% if options.only_invite_if_the_order_contains_a_product_with_this_tag == blank %}
    {% assign order_qualifies = true %}
  {% else %}
    {% for line_item in order.line_items %}
      {% assign product_tags = line_item.product.tags | split: ", " %}
      {% if product_tags contains options.only_invite_if_the_order_contains_a_product_with_this_tag %}
        {% assign order_qualifies = true %}
        {% break %}
      {% endif %}
    {% endfor %}
  {% endif %}
{% endif %}

{% if order.customer == nil %}
  {% log message: "Order does not have a customer; skipping invitation" %}
{% elsif customer_qualifies == false %}
  {% log message: "Customer does not qualify for an invitation", customer_state: order.customer.state, customer_tags: order.customer.tags %}
{% elsif order_qualifies == false and options.only_invite_if_the_order_contains_a_product_with_this_tag != blank %}
  {% log message: "No qualifying product found", required_product_tag: options.only_invite_if_the_order_contains_a_product_with_this_tag %}
{% endif %} 

{% if order_qualifies %}
  {% assign customer_invite = hash %}

  {% if options.custom_invitation_email_subject != blank %}
    {% assign customer_invite["subject"] = options.custom_invitation_email_subject %}
  {% endif %}

  {% if options.custom_invitation_email_message__multiline != blank %}
    {% assign customer_invite["custom_message"] = options.custom_invitation_email_message__multiline %}
  {% endif %}

  {% if options.invitation_email_bcc__array != blank %}
    {% assign customer_invite["bcc"] = options.invitation_email_bcc__array %}
  {% endif %}

  {% action "shopify" %}
    [
      "post",
      "/admin/customers/{{ order.customer.id | json }}/send_invite.json",
      {
        "customer_invite": {{ customer_invite | json }}
      }
    ]
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more