-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.liquid
44 lines (40 loc) · 1.04 KB
/
script.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{% if event.preview %}
{% capture order_json %}
{
"admin_graphql_api_id": "gid://shopify/Order/12345",
"customer": {
"note": {{ options.tag_prefix_in_customer_note__required | append: "abc123" | json }}
}
}
{% endcapture %}
{% assign order = order_json | parse_json %}
{% endif %}
{% assign note_lines = order.customer.note | split: newline %}
{% assign desired_prefix = options.tag_prefix_in_customer_note__required %}
{% assign tag = nil %}
{% for line in note_lines %}
{% assign line_prefix = line | slice: 0, desired_prefix.size %}
{% if line_prefix == desired_prefix %}
{% assign tag = line | replace: line_prefix, "" %}
{% endif %}
{% endfor %}
{% if tag != blank %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ tag | json }}
) {
node {
... on Order {
tags
}
}
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}