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

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

Remove a product tag when another tag is added

Does exactly as it says. :)

Runs Occurs whenever a product is updated, ordered, or variants are added, removed or updated. Configuration includes product tag to watch for, product 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/products/update
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
product tag to watch for (required), product tag to remove (required), ignore tag case (boolean)
Code
{% if event.preview %}
  {% assign product = hash %}
  {% assign product["admin_graphql_api_id"] = "gid://shopify/Product/1234567890" %}
  {% assign product["tags"] = options.product_tag_to_watch_for__required | append: ", " | append: options.product_tag_to_remove__required %}
{% endif %}

{% assign product_tags = product.tags | split: ", " %}
{% assign tag_to_match = options.product_tag_to_watch_for__required %}
{% assign tag_to_remove = options.product_tag_to_remove__required %}

{% if options.ignore_tag_case__boolean %}
  {% assign product_tags = product.tags | downcase | split: ", " %}
  {% assign tag_to_match = options.product_tag_to_watch_for__required | downcase %}
  {% assign tag_to_remove = options.product_tag_to_remove__required | downcase %}
{% endif %}

{% if product_tags contains tag_to_match and product_tags contains tag_to_remove %}
  {% action "shopify" %}
    mutation {
      tagsRemove(
        id: {{ product.admin_graphql_api_id | json }}
        tags: {{ options.product_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
Ignore tag case
true