Auto-untag customers when a certain product is refunded
Use this task to automatically remove a certain customer tag whenever a particular product is refunded, for that customer.
Try this taskWhen it runs
Occurs whenever a new refund is created without errors on an order, independent from the movement of money
What you choose
- Product IDs
- Customer tag to remove
Documentation
Use this task to automatically remove a certain customer tag whenever a particular product is refunded, for that customer.
This task is configured with one or more product IDs (learn how to find a product ID), and with the customer tag to remove when one of those products is refunded.
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/refunds/create
How task subscriptions work
Option types and flags
- Product IDs (number, array, required)
- Customer tag to remove (required)
Task code
{% if event.preview %}
{% assign refund = hash %}
{% assign refund["refund_line_items"] = array %}
{% assign refund["refund_line_items"][0] = hash %}
{% assign refund["refund_line_items"][0]["line_item"] = hash %}
{% assign refund["refund_line_items"][0]["line_item"]["product_id"] = options.product_ids__number_array_required.first %}
{% assign refund["order"] = hash %}
{% assign refund["order"]["customer"] = hash %}
{% assign refund["order"]["customer"]["admin_graphql_api_id"] = "gid://shopify/Customer/1234567890" %}
{% assign refund["order"]["customer"]["tags"] = options.customer_tag_to_remove__required %}
{% endif %}
{% assign refunded_product_ids = refund.refund_line_items | map: "line_item" | map: "product_id" %}
{% assign refund_qualifies = false %}
{% for product_id in options.product_ids__number_array_required %}
{% if refunded_product_ids contains product_id %}
{% assign refund_qualifies = true %}
{% break %}
{% endif %}
{% endfor %}
{% assign customer = refund.order.customer %}
{% assign customer_tags = refund.order.customer.tags | split: "," %}
{% if refund_qualifies and customer_tags contains options.customer_tag_to_remove__required %}
{% action "shopify" %}
mutation {
tagsRemove(
id: {{ customer.admin_graphql_api_id | json }}
tags: {{ options.customer_tag_to_remove__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
Mechanic Liquid reference