Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shopify - prepopulate billing address based on query param

I am trying to prepopulate the shipping/billing address in Shopify checkout via URL query params. I've found this is easy to do with the shipping address as referenced here:

https://community.shopify.com/c/Shopify-APIs-SDKs/Autofill-checkout-fields/td-p/318793

But when I try to do the same with the billing info, the "Same as shipping address" radio is always selected on the payment screen and if I manually select the option for a different address, all values are blank

How can I prepopulate both addresses? I've tried adding the billing query params directly to the checkout payment page URL, but that does not work either. Here is the URL I've been trying:

demo-store.myshopify.com/checkout?checkout[email][email protected]&checkout[shipping_address][first_name]=John&checkout[shipping_address][last_name]=Doe&checkout[shipping_address][address1]=333%20Fake%20St.&checkout[shipping_address][city]=San%20Diego&checkout[shipping_address][province]=CA&checkout[shipping_address][country]=USA&checkout[shipping_address][zip]=92116&checkout[shipping_address][phone]=333-333-3333&checkout[different_billing_address]=true&checkout[billing_address][first_name]=Jane&checkout[billing_address][last_name]=Doe&checkout[billing_address][address1]=444%20Fake%20St%20&checkout[billing_address][city]=San%20Diego&checkout[billing_address][province]=CA&checkout[billing_address][country]=USA&checkout[billing_address][zip]=92121&checkout[billing_address][phone]=444-444-4444

Also, bonus question, the shipping state always seems to be populated based on IP address, so even if I pass it a value, it shows the state I'm in. How can I get it to always reflect the value of the query param?

like image 566
Cook88 Avatar asked Apr 29 '20 18:04

Cook88


1 Answers

To create a prepopulated checkout on Shopify, you will need to supply the checkout through either the Admin API or the Storefront API

To create a checkout and return the web URL, send a POST request to the admin/checkouts.json endpoint.

Depending on how you choose to do this it can be achieved with many different points of access, as referenced in the Shopify Dev portal, though you will not be able to complete this in the requested manner using only URL parameters.

For further reading, please refer to the Getting started for the Storefront API and the Storefront API Checkout Object

like image 100
AudioShox Avatar answered Nov 16 '22 12:11

AudioShox