New Shopify Certification now available: Liquid Storefronts for Theme Developers

How to get the discount code in the script on the payment page?

sandroid
Visitor
2 0 1

Help who can...

To send order data to the Google Tag Manager I add the following script in the settings of the Checkout section:

 

{% if first_time_accessed %}
  dataLayer.push({
  event: "purchase",
  ecommerce: {
    transaction_id: "{{ order.order_number || order.name }}",
    value: {{ total_price | times: 0.01 }},
    tax: {{ tax_price | times: 0.01 }},
    shipping: {{ shipping_price | times: 0.01 }},
    currency: "{{ order.currency }}",
    discount: "????????????????????????????????????",
    items: [
       {% for line_item in line_items %}{
         item_id: "{{ line_item.product_id }}",
         discount: "??????????????????????",
         item_name: "{{ line_item.variant.title || line_item.title }}",
         currency: "{{ order.currency || shop.currency }}",
         price: "{{ line_item.final_price | times: 0.01 }}",
         quantity: "{{ line_item.quantity }}"
       },

{% endfor %}
]
}
});

 

Everything works well. Except I don't know how to get coupon information (code). I need to send a discount code in the "discount" field.

Can you please suggest me the object and property. I couldn't find it in the documentation. Tried experimenting with "discount_applications" but couldn't get anything from it (I have no experience with with LiquidJS and how show object in console by it)

 
Replies 2 (2)
sandroid
Visitor
2 0 1

Is this at all even possible? In particular, when the tariff version is not a Plus.

webhasan
Shopify Partner
1 0 0

You can use following code for total discount

discount: {{ checkout.discounts_amount | times: 0.01 }}

 

For item level discount use following code 

discount': {{ line_item.line_level_total_discount | times: 0.01 }}