Mechanic Get Mechanic
Task library

Remove a product tag when another tag is added

Does exactly as it says. :)

Try this task

When it runs

Occurs whenever a product is updated, ordered, or variants are added, removed or updated

What you choose

  • Product tag to watch for
  • Product tag to remove
  • Ignore tag case
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/products/update
How task subscriptions work

Option types and flags

Task 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 %}
Mechanic Liquid reference

Default option values

Ignore tag case
true