Remove an order tag when another tag is added, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Remove an order tag when another tag is added

Does exactly as it says. :)

Runs Occurs whenever an order is updated. Configuration includes order tag to watch for, order 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, Shopifolks, 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.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
shopify/orders/updated
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
order tag to watch for (required) , order tag to remove (required) , ignore tag case (boolean)
Code
{% if event.preview %}
  {% assign order = hash %}
  {% assign order["admin_graphql_api_id"] = "gid://shopify/Order/1234567890" %}
  {% assign order["tags"] = options.order_tag_to_watch_for__required | append: ", " | append: options.order_tag_to_remove__required %}
{% endif %}

{% assign order_tags = order.tags | split: ", " %}
{% assign tag_to_match = options.order_tag_to_watch_for__required %}
{% assign tag_to_remove = options.order_tag_to_remove__required %}

{% if options.ignore_tag_case__boolean %}
  {% assign order_tags = order.tags | downcase | split: ", " %}
  {% assign tag_to_match = options.order_tag_to_watch_for__required | downcase %}
  {% assign tag_to_remove = options.order_tag_to_remove__required | downcase %}
{% endif %}

{% if order_tags contains tag_to_match and order_tags contains tag_to_remove %}
  {% action "shopify" %}
    mutation {
      tagsRemove(
        id: {{ order.admin_graphql_api_id | json }}
        tags: {{ options.order_tag_to_remove__required | json }}
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Order tag to watch for
apple
Order tag to remove
butter
Ignore tag case
true