Post Purchase Scripts Not Executing As Expected

brianpuzzles
Visitor
3 0 1

I need to get the customer id on the "thank_you" page. I'm expecting either a liquid script {{ order.customer.id }} or javascript window.Shopify.checkout.customer_id to store this information. 

 

There are 2 issues:

1. The post purchase scripts (settings -> checkout -> "Post-purchase page") aren't running

2. The customer id is null on the "thank_you" page

 

Steps to reproduce:

Order status page script:

<script>
console.log("order status");
console.log("{{ order.customer.id}}");
</script>

Post Purchase Page script:

<script>
console.log("post-purchase");
</script>

result:

Screen Shot 2022-12-21 at 6.21.54 AM.png

 

This is the "thank_you" page. I'm expecting the post purchase script to run and there to be some reference to the customer id in either liquid or global shopify object. Inspecting window.Shopify results in only null's for customer data. 

 

Upon reload of the page, the "order status" page, the customer id appears from liquid:

Screen Shot 2022-12-21 at 6.22.03 AM.png

 

Any insights would helpful. Thanks

Reply 1 (1)

soulchild37
Shopify Partner
166 9 46

I have just tried this on my own store and it seems to work.

For the post-purchase thank you page, we can only access the {{ checkout }} liquid object directly  (the {{ order }} is not available), you can reference the checkout liquid object here : https://shopify.dev/docs/api/liquid/objects/checkout

To get the order id, you can use {{ checkout.order_id }}, to get other order attribute such as customer id, you can use {{ checkout.order.customer.id }}  etc.

Hope this can help

Spent too much support time dealing with order cancellation request from customer? Wouldn't it be good if customer can cancel order on their own without bugging your support? Try out Cancellable app! https://apps.shopify.com/cancellable . I also write articles about store customization that can improve your customer shopping experience here : Yagi Software Blog