Remove a customer tag when another tag is added, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Remove a customer tag when another tag is added

by Mechanic Team (team@usemechanic.com)

Does exactly as it says. :)

Runs when a customer is updated. Configuration includes customer tag to watch for, customer tag to remove, and ignore tag case.

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 a customer is updated (shopify/customers/update)
Options
customer tag to watch for (required), customer tag to remove (required), ignore tag case (boolean)
Script
{% assign customer_tags = customer.tags | split: ", " %}
{% assign tag_to_match = options.customer_tag_to_watch_for__required %}
{% assign tag_to_remove = options.customer_tag_to_remove__required %}

{% if options.ignore_tag_case__boolean %}
  {% assign customer_tags = customer.tags | downcase | split: ", " %}
  {% assign tag_to_match = options.customer_tag_to_watch_for__required | downcase %}
{% endif %}

{% assign customer_qualifies = false %}
{% if customer_tags contains tag_to_match and customer_tags contains tag_to_remove %}
  {% assign customer_qualifies = true %}
{% endif %}

{% assign customer_id = customer.reload.admin_graphql_api_id %}
{% if event.preview %}
  {% assign customer_id = "gid://shopify/Customer/1234567890" %}
{% endif %}

{% if event.preview or customer_qualifies %}
  {% capture query %}
    mutation {
      tagsRemove(
        id: {{ customer_id | json }}
        tags: {{ tag_to_remove | json }}
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endcapture %}

  {% action "shopify" query %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Ignore tag case
true