Auto-invite customers when tagged, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Auto-invite customers when tagged

by Isaac Bowen (team@usemechanic.com)

This task watches for updates to customers, and sends invites for any customer who has the tag you choose, who hasn't previously been invited. This task also supports sending invitations in bulk, to all tagged customers who haven't previously been invited.

Runs when a customer is created, when a customer is updated, and when a user triggers the task. Configuration includes tag to watch for, ignore tag case, invitation email subject, and invitation email body.

15-day free trial – unlimited tasks

Documentation

This task watches for updates to customers, and sends invites for any customer who has the tag you choose, who hasn't previously been invited.

Use the "Run task" button to send invites to all of your previously-uninvited customers who have the configured tag.

Invitation emails are sent using your store's account invite notification email template. Learn how to update this template.

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 a customer is created (shopify/customers/create)
when a customer is updated (shopify/customers/update)
when a user triggers the task (mechanic/user/trigger)
Options
tag to watch for (required), ignore tag case (boolean), invitation email subject (required), invitation email body (multiline, required)
Script
{% assign customers = array %}

{% if event.preview %}
  {% assign customers[0] = hash %}
  {% assign customers[0]["id"] = 1234567890 %}
{% elsif event.topic contains "shopify/customers/" %}
  {% assign customer_qualifies = true %}

  {% assign customer_tags = customer.tags | split: ", " %}
  {% assign tag = options.tag_to_watch_for__required %}

  {% if options.ignore_tag_case__boolean %}
    {% assign customer_tags = customer.tags | downcase | split: ", " %}
    {% assign tag = tag | downcase %}
    {% unless customer_tags contains tag %}
      {% assign customer_qualifies = false %}
    {% endunless %}
  {% else %}
    {% unless customer_tags contains tag %}
      {% assign customer_qualifies = false %}
    {% endunless %}
  {% endif %}

  {% if customer.state != "disabled" %}
    {% assign customer_qualifies = false %}
  {% endif %}

  {% if customer_qualifies %}
    {% assign customers[customers.size] = customer %}
  {% endif %}
{% elsif event.topic == "mechanic/user/trigger" %}
  {% assign query = "tag:" | append: approval_tag | append: " state:disabled" %}
  {% assign customers = shop.customers.search[query] %}
{% endif %}

{% for customer in customers %}
  {% action "shopify" %}
    [
      "post",
      "/admin/customers/{{ customer.id | json }}/send_invite.json",
      {
        "customer_invite": {
          "subject": {{ options.invitation_email_subject__required | json }},
          "custom_message": {{ options.invitation_email_body__multiline_required | json }}
        }
      }
    ]
  {% endaction %}
{% endfor %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Tag to watch for
invite
Ignore tag case
true
Invitation email subject
Your account is ready!
Invitation email body
Your account for {{ shop.name }} has been pre-approved! Use the button below to get started.