Auto-invite customers after an order with Mechanic.

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

Auto-invite customers after an order

by Isaac Bowen (team@usemechanic.com)

Automatically prompt customers to activate their customer accounts, after placing an order in your store – 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 order contains a product with this tag, invitation email subject, and invitation email body.

15-day free trial – unlimited tasks

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 created (shopify/orders/create)
Options
only invite if the order contains a product with this tag, invitation email subject (required), invitation email body (multiline, required)
Script
{% assign customer_qualifies = false %}
{% if order.customer and order.customer.state != "enabled" %}
  {% assign customer_qualifies = true %}
{% 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 }}; 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": {
      "type": "shopify",
      "options": [
        "post",
        "/admin/customers/{{ order.customer.id | json }}/send_invite.json",
        {
          "customer_invite": {
            "subject": {{ options.invitation_email_subject__required | json }},
            "custom_message": {{ options.invitation_email_body__multiline_required | json }}
          }
        }
      ]
    }
  }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Only invite if the order contains a product with this tag
autoinvite
Invitation email subject
Activate your account
Invitation email body
Thanks for purchasing access! Use this link to activate your new account at {{ shop.name }}.