-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout-snippet.liquid
48 lines (45 loc) · 1.74 KB
/
checkout-snippet.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
45
46
47
48
{% comment %}
Export cart contents for shopify-gtm-instrumentor such that they are similar
to the schema from the Storefront API.
{% endcomment %}
<script>
window.CHECKOUT_FOR_GTM_INSTRUMENTOR = {
id: {{ checkout.id }},
subtotalPrice: '{{ checkout.line_items_subtotal_price | money_without_currency }}',
totalPrice: '{{ checkout.total_price | money_without_currency }}',
lineItems: [],
{% comment %} Properties that aren't present until purchase {% endcomment %}
orderNumber: '{{ checkout.order_number }}',
totalTax: '{{ checkout.tax_price | money_without_currency }}',
totalShipping: '{{ checkout.shipping_price | money_without_currency }}',
discountCodes: [],
};
{% comment %} Add line items {% endcomment %}
{% for line_item in checkout.line_items %}
CHECKOUT_FOR_GTM_INSTRUMENTOR.lineItems.push({
id: {{ line_item.id | json }},
quantity: {{ line_item.quantity }},
variant: {
id: {{ line_item.variant.id | json }},
sku: {{ line_item.variant.sku | json }},
title: {{ line_item.variant.title | json }},
price: '{{ line_item.variant.price | money_without_currency }}',
compareAtPrice: '{{ line_item.variant.compare_at_price | money_without_currency }}',
image: {{ line_item.image.src | json }},
product: {
id: {{ line_item.product.id | json }},
title: {{ line_item.product.title | json}},
handle: {{ line_item.product.handle | json }},
productType: {{ line_item.product.type | json }},
vendor: {{ line_item.product.vendor | json }},
},
},
});
{% endfor %}
{% comment %} Add discount codes {% endcomment %}
{% for discount in checkout.discounts_amount %}
CHECKOUT_FOR_GTM_INSTRUMENTOR.discountCodes.push({
code: {{ discount.title | json }},
});
{% endfor %}
</script>