Mechanic Get Mechanic
Task library

Auto-delete customers that are created without orders

Useful for stores that are subjected to bot abuse, this task watches for newly-created customers, and deletes any that don't come with an associated order. Optionally, choose to ignore any customers that are created with a certain tag – helpful if you create customers yourself, via the Shopify admin.

Try this task

When it runs

Occurs whenever a customer is created

What you choose

Ignore customers having this tag

Task code and subscriptions

You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.

Subscriptions

shopify/customers/create
How task subscriptions work

Task code

{% assign delete_customer = false %}

{% if customer.orders.first == nil %}
  {% log "Customer has no orders" %}
  {% assign delete_customer = true %}
{% endif %}

{% if options.ignore_customers_having_this_tag != blank %}
  {% assign customer_tags = customer.tags | split: ", " %}
  {% if customer_tags contains options.ignore_customers_having_this_tag %}
    {% log "Customer had a whitelisted tag; ignoring" %}
    {% assign delete_customer = false %}
  {% endif %}
{% endif %}

{% if event.preview or delete_customer %}
  {% action "shopify" %}
    [
      "delete",
      ["customer", {{ customer.id | json }}]
    ]
  {% endaction %}
{% endif %}
Mechanic Liquid reference