Auto-tag products without descriptions, with Mechanic.

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

Auto-tag products without descriptions

This task runs when products are updated, checking if they have a description, and tagging them if not. Once a description has been added, then the tag will be removed.

Runs Occurs whenever a product is updated, ordered, or variants are added, removed or updated and Occurs when a user manually triggers the task. Configuration includes tag to apply.

15-day free trial – unlimited tasks

Documentation

This task runs when products are updated, checking if they have a description, and tagging them if not. Once a description has been added, then the tag will be removed.

You may also run the task manually to scan your entire product catalog,

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
mechanic/user/trigger
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
tag to apply (required)
Code
{% assign tag_to_apply = options.tag_to_apply__required %}

{% assign products = array %}

{% if event.topic == "shopify/products/update" %}
  {% capture query %}
    query {
      product(id: {{ product.admin_graphql_api_id | json }}) {
        id
        descriptionHtml
        tags
      }
    }  
  {% endcapture %}
  
  {% assign result = query | shopify %}
  {% assign products[0] = result.data.product %}

{% elsif event.topic == "mechanic/user/trigger" %}
  {% assign cursor = nil %} 
  
  {% for n in (1..200) %}
    {% capture query %}
      query {
        products(
          first: 250
          after: {{ cursor | json }}
        ) {
          pageInfo {
            hasNextPage
            endCursor
          }
          nodes {
            id
            descriptionHtml
            tags
          }
        }
      }
    {% endcapture %}
  
    {% assign result = query | shopify %}
    
    {% assign products
      = result.data.products.nodes
      | default: array
      | concat: products
    %}
  
    {% if result.data.products.pageInfo.hasNextPage %}
      {% assign cursor = result.data.products.pageInfo.endCursor %}
    {% else %}
      {% break %}
    {% endif %}
  {% endfor %} 
{% endif %}

{% if event.preview %}
  {% assign products[0] = hash %}
  {% assign products[0]["id"] = "gid://shopify/Product/1234567890" %}
{% endif %}

{% for product in products %}
  {% if product.descriptionHtml == blank %}
    {% unless product.tags contains tag_to_apply %}
      {% action "shopify" %}
        mutation {
          tagsAdd(
            id: {{ product.id | json }}
            tags: {{ tag_to_apply | json }}
          ) {
            userErrors {
              field
              message
            }
          }
        }
      {% endaction %}        
    {% endunless %}

  {% elsif product.tags contains tag_to_apply %}
    {% action "shopify" %}
      mutation {
        tagsRemove(
          id: {{ product.id | json }}
          tags: {{ tag_to_apply | json }}
        ) {
          userErrors {
            field
            message
          }
        }
      }
    {% endaction %}
  {% endif %}
{% endfor %} 
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more