FROM CACHE - en_header

Shopify Post-Purchase Checkout Extension - How to get the order Id?

zahid
Shopify Partner
21 4 4

I have created a basic Shopify post-purchase checkout extension, using this tutorial : https://shopify.dev/apps/checkout/post-purchase/update-an-order-for-a-checkout-post-purchase-app-ext...

The buyer sees the post purchase page after they have placed an order and can add a product to their existing order. I want to know the order Id of the edited order, so I can tag it with my app's name.

I have not been able to find a way to get the order Id of the initial purchase. Need some help with this please!

Creator of StoreView, an app that lets you view your customers' journey as they interact with your store.
Replies 6 (6)
kyle_truong
Shopify Partner
55 6 12

Any updates to this?

I'm facing similar issues and I'm thinking of matching referenceIds between the shouldRender Input data and the order webhooks to get the order id but this feels more complicated than it should be, and I'm not even sure if it'll work.

zahid
Shopify Partner
21 4 4

Hey,

You are on the right path, but you won't be able to match reference Ids, as they don't appear in the order webhook payload.

Instead you will need to set a metafield when calling signchangeset. The "changes" variable that looks like : 

 

[{type: 'add_variant', variantId: variantID, quantity: 1}]

 

will become : 

 

[{type: 'add_variant', variantId: variantID, quantity: 1},{type: "set_metafield", namespace: "{your app name}", key: "isUpsellOrder", value: 1, valueType: "integer"}]

 

Once this is done, then on the server side you will need to subscribe to the order webhook and check for the "isUpsellOrder" metafield by calling the Order API's metafields endpoint:

 

$metafieldData = $shopifyClient->call('GET', '/admin/api/2021-07/orders/'.$orderId.'/metafields.json');

 

Parse through the metafield data and see if isUpsellOrder is true. This way you can connect your upsell order to the order Id.

 

 

Creator of StoreView, an app that lets you view your customers' journey as they interact with your store.
kyle_truong
Shopify Partner
55 6 12

Thank you! I was confused about metafields too and this clears it up.

I should also mention I did some testing last night and it looks like the "referenceId" can be matched to the order webhook's "checkout_token". I'm not sure how consistent this is but I'll be doing more testing today.

zahid
Shopify Partner
21 4 4

I think you are right! Looking forward to know what you find out after testing. 

 

This would make things much more simpler!

Creator of StoreView, an app that lets you view your customers' journey as they interact with your store.
kyle_truong
Shopify Partner
55 6 12

It's looking pretty good, everything's working as expected for me when using referenceId as the checkoutToken.  

Joelket
Shopify Partner
2 0 0

Thanks I did the same for now.