What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to have custom pricing reflected in checkout

Solved

How to have custom pricing reflected in checkout

thepig
Tourist
3 1 2

This is more a "how does it work" question.  When an app does custom pricing, it is straight forward enough to have that pricing be shown on the site and in the cart using just liquid and javascript.  I am curious how to make sure the custom pricing is reflected in the checkout when the transition is made from cart (correct pricing showing) to checkout (needs same pricing as cart).

My thoughts are that you could listen on a webhook for checkout create and then update the checkout object with the correct pricing.  I'm not sure if this would happen fast enough to make sure it shows for the customer on checkout render.

Any ideas how the various custom pricing apps achieve this?

Accepted Solution (1)

thepig
Tourist
3 1 2

This is an accepted solution.

For anybody who is looking at how to do this.

You need to have the "Checkout / Place Order" button on the cart make a request to an endpoint you control.   This endpoint will need to create a draft order, which you can then apply whatever logic you want to the line items.  You then return the invoice url in the response (Ex: "invoice_url": "https://jsmith.myshopify.com/548380009/invoices/ba8dcf6c022ccad3d47e3909e378e33f",) which is provided by shopify via the https://shopify.dev/api/admin-rest/2021-10/resources/draftorder#[get]/admin/api/2021-10/draft_orders... API.  

You send the user to this URL, which then forwards the user to a checkout which shows the content of this order for the user to checkout.

View solution in original post

Reply 1 (1)

thepig
Tourist
3 1 2

This is an accepted solution.

For anybody who is looking at how to do this.

You need to have the "Checkout / Place Order" button on the cart make a request to an endpoint you control.   This endpoint will need to create a draft order, which you can then apply whatever logic you want to the line items.  You then return the invoice url in the response (Ex: "invoice_url": "https://jsmith.myshopify.com/548380009/invoices/ba8dcf6c022ccad3d47e3909e378e33f",) which is provided by shopify via the https://shopify.dev/api/admin-rest/2021-10/resources/draftorder#[get]/admin/api/2021-10/draft_orders... API.  

You send the user to this URL, which then forwards the user to a checkout which shows the content of this order for the user to checkout.