Auto-invite customers after an order, with Mechanic.

Mechanic is a development 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 when 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, invitation email subject, and invitation email custom message.

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, 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.

Open source
View on GitHub to contribute to this task
Events
when an order is created (shopify/orders/create)
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, invitation email subject (required), invitation email custom message (multiline)
Script
{% 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.invitation_email_subject__required }}
  {{ options.invitation_email_custom_message__multiline }}
{% endcomment %}

{% 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 %}
  {% capture message %}Order does not have a customer; skipping invitation"}{% endcapture %}
  {"log": {{ message | json }}}
{% elsif customer_qualifies == false %}
  {% capture message %}Customer state is {{ order.customer.state | json }} with tags {{ order.customer.tags | json }}; skipping invitation"}{% endcapture %}
  {"log": {{ message | json }}}
{% elsif order_qualifies == false and options.only_invite_if_the_order_contains_a_product_with_this_tag != blank %}
  {% capture message %}No product found in the order with the tag {{ options.only_invite_if_the_order_contains_a_product_with_this_tag | json }}; skipping invitation"}{% endcapture %}
  {"log": {{ message | json }}}
{% endif %} 

{% if event.preview or order_qualifies %}
  {% action "shopify" %}
    [
      "post",
      "/admin/customers/{{ order.customer.id | json }}/send_invite.json",
      {
        "customer_invite": {
          "subject": {{ options.invitation_email_subject__required | json }},
          "custom_message": {{ options.invitation_email_custom_message__multiline | 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
Invitation email subject
Activate your account
Invitation email custom message
Hi there,

Thanks for purchasing access! Activate your new account at {{ shop.name }}.

Thanks,
{{ shop.name }}