Auto-tag new orders based on payment method with Mechanic.

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

Auto-tag new orders based on payment method

by Isaac Bowen (team@usemechanic.com)

This task checks the payment method for new orders immediately upon order creation, and tags the order accordingly. (If you need to tag the order later on, based on updates or when the order is paid, get in touch!)

Runs when an order is created. Configuration includes payment gateway name and comma separated tags to add.

15-day free trial – unlimited tasks

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 an order is created (shopify/orders/create)
Options
payment gateway name (required), comma separated tags to add (required)
Script
{% assign order_qualifies = false %}
{% if order.payment_gateway_names contains options.payment_gateway_name__required %}
  {% assign order_qualifies = true %}
{% endif %}

{% if event.preview or order_qualifies %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "order",
          {{ order.id }}
        ],
        {
          "tags": {{ options.comma_separated_tags_to_add__required | json }}
        }
      ]
    }
  }
{% endif %}

{% if event.preview != true and order_qualifies != true %}
  {% capture log_message %}
    The order did not qualify for auto-tagging. This task is configured to look for {{ options.payment_gateway_name__required | json }}; this order was paid using {{ order.payment_gateway_names | json }}.
  {% endcapture %}

  { "log": {{ log_message | strip | json }} }
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.