Auto-tag customers who purchase an item on sale, with Mechanic.

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

Auto-tag customers who purchase an item on sale

When a customer orders an item on sale (technically, when the order contains a product variant that includes a "compare at" price), this task automatically adds a tag to their account. Useful for keeping track of customers who take advantage of sale pricing!

Runs Occurs whenever an order is created and Occurs when a user manually triggers the task. Configuration includes tag to add.

15-day free trial – unlimited tasks

Documentation

When a customer orders an item on sale (technically, when the order contains a product variant that includes a "compare at" price), this task automatically adds a tag to their account. Useful for keeping track of customers who take advantage of sale pricing!

This task will run for each new order that's created, tagging customers who purchase a product that has a "compare at" price.

Run this task manually to have Mechanic scan your entire customer base, and each customer's order history. This may take some time! To ensure that Mechanic can access your complete history, make sure "Read all orders" is enabled.

Please note: This task will only tag customers who've purchased a product that currently has a "compare at" price. Historical information about "compare at" pricing is not available, and so this task cannot make tagging decisions based on historical pricing.

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/orders/create
mechanic/user/trigger
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
tag to add (required)
Code
{% if event.preview %}
  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "customer",
          1234567890
        ],
        {
          "tags": {{ options.tag_to_add__required | json }}
        }
      ]
    }
  }
{% elsif event.topic contains "shopify/orders/" %}
  {% assign customer = order.customer.reload %}

  {% assign purchase_includes_compare_at_pricing = false %}

  {% for line_item in order.line_items %}
    {% if line_item.variant.compare_at_price != blank %}
      {% assign purchase_includes_compare_at_pricing = true %}
      {% break %}
    {% endif %}
  {% endfor %}

  {% if purchase_includes_compare_at_pricing %}
    {% assign customer_tags_to_save = customer.tags | add_tag: options.tag_to_add__required %}

    {% if customer.tags != customer_tags_to_save %}
      {
        "action": {
          "type": "shopify",
          "options": [
            "update",
            [
              "customer",
              {{ customer.id | json }}
            ],
            {
              "tags": {{ customer_tags_to_save | json }}
            }
          ]
        }
      }
    {% endif %}
  {% endif %}
{% elsif event.topic == "mechanic/user/trigger" %}
  {% for customer in shop.customers %}
    {% assign customer_tags_to_save = customer.tags %}
    {% assign purchase_includes_compare_at_pricing = false %}

    {% for order in customer.orders.any %}
      {% for line_item in order.line_items %}
        {% if line_item.variant.compare_at_price != blank %}
          {% assign purchase_includes_compare_at_pricing = true %}
          {% break %}
        {% endif %}
      {% endfor %}

      {% if purchase_includes_compare_at_pricing %}
        {% assign customer_tags_to_save = customer.tags | add_tag: options.tag_to_add__required %}
        {% break %}
      {% endif %}
    {% endfor %}

    {% if customer_tags_to_save != customer.tags %}
      {
        "action": {
          "type": "shopify",
          "options": [
            "update",
            [
              "customer",
              {{ customer.id | json }}
            ],
            {
              "tags": {{ customer_tags_to_save | json }}
            }
          ]
        }
      }
    {% endif %}
  {% endfor %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Tag to add
discount-shopper