Discussing APIs and development related to customers, discounts, and order management.
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:
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:
Any insights would helpful. Thanks
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