Auto-tag orders with chargeback or inquiry activity with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Auto-tag orders with chargeback or inquiry activity

by Isaac Bowen (team@usemechanic.com)

Stay on top of chargebacks and inquiries! Nightly or on-demand, this task will scan the last 60 days of your order records, and apply the tags of your choice to orders with chargeback or inquiry activity, based on what that activity looks like.

Runs when a user triggers the task and every day at midnight. Configuration includes tag for any, tag for open, tag for submitted, tag for won, and tag for lost.

15-day free trial – unlimited tasks

Documentation

Nightly or on-demand, this task scans the last 60 days of your order records, and apply the tags of your choice to orders with chargeback or inquiry activity, based on where that process is for each order.

Learn more about chargebacks in the Shopify documentation:

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 user triggers the task (mechanic/user/trigger)
every day at midnight (mechanic/scheduler/daily)
Options
tag for any, tag for open, tag for submitted, tag for won, tag for lost
Script
{% if event.preview %}
  {% assign preview_tag = options.tag_for_any | default: options.tag_for_open | default: options.tag_for_submitted | default: options.tag_for_won | default: options.tag_for_lost %}

  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "order",
          12345
        ],
        {
          "tags": {{ preview_tag | json }}
        }
      ]
    }
  }
{% else %}
  {% assign statuses = "open,submitted,won,lost,any" | split: "," %}

  {% for status in statuses %}
    {% assign option_key = "tag_for_" | append: status %}

    {% assign chargeback_filter_key = "chargeback_" | append: status %}
    {% for order in shop.orders[chargeback_filter_key] %}
      {% assign tags_to_save = order.tags | add_tag: options[option_tag_key] %}

      {% if status == "submitted" %}
        {% assign tags_to_save = tags_to_save | remove_tag: options.tag_for_open %}
      {% elsif status == "won" or status == "lost" %}
        {% assign tags_to_save = tags_to_save | remove_tag: options.tag_for_open | remove_tag: options.tag_for_submitted %}
      {% endif %}

      {% if tags_to_save != order.tags %}
        {
          "action": {
            "type": "shopify",
            "options": [
              "update",
              [
                "order",
                {{ order.id | json }}
              ],
              {
                "tags": {{ tags_to_save | json }}
              }
            ]
          }
        }
      {% endif %}
    {% endfor %}
  {% endfor %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Tag for any
chargeback-any
Tag for open
chargeback-open
Tag for submitted
chargeback-submitted
Tag for won
chargeback-won
Tag for lost
chargeback-lost