Mechanic is a development and ecommerce automation platform for Shopify. :)
This task automatically adds the tag of your choice to incoming orders, based on the country in the order's shipping address.
Runs Occurs whenever an order is created. Configuration includes tags to apply and country codes.
This task automatically adds the tag of your choice to incoming orders, based on the country in the order's shipping address.
Begin by clicking the Add item link next to the Tags to apply and country codes field. Enter tags on the left (one per row), and for each tag add one or more two-character country codes on the right, separated by commas. Country codes should be entered in all caps. Find country codes here.
Example input: Central America > BZ,CR,SV,GT,HN,NI,PA
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?)
shopify/orders/create
{% assign tags_to_apply_and_country_codes = options.tags_to_apply_and_country_codes__keyval_required %} {% if event.preview %} {% assign order = '{"admin_graphql_api_id": "gid://shopify/Order/1234567890"}' | parse_json %} {% assign order["shipping_address"] = hash %} {% assign order["shipping_address"]["country_code"] = tags_to_apply_and_country_codes.first.last %} {% endif %} {% for tag_to_apply_and_country_codes in tags_to_apply_and_country_codes %} {% if tag_to_apply_and_country_codes.last contains order.shipping_address.country_code %} {% action "shopify" %} mutation { tagsAdd( id: {{ order.admin_graphql_api_id | json }} tags: {{ tag_to_apply_and_country_codes.first | json }} ) { userErrors { field message } } } {% endaction %} {% break %} {% endif %} {% endfor %}