On top of adding products to cart via URL and redirect to checkout, there is a way to also fill out the Checkout page input fields within the same link.
This could be super handy when you know the billing/shipping details of a registered or guest customer and want to speed up the order process.
It’s important to note that the URL will need to contain personal data e.g. email address, billing address, phone number, and so on; you need to make sure the URL is only shared with the specific customer (in an email, for example, as content is tailored to the subscriber; or only when the WooCommerce customer is logged in if you’re using the URL behind a website button).
Once that’s clear, let’s go ahead, and let’s see how my WooCommerce snippet works. Enjoy!

PHP Snippet: Populate WooCommerce Checkout Billing & Shipping Via URL
Notes:
1) Once the snippet is installed, you can use the following URL format (in bold you see the URL parameters you must use, and they need to be identical to the ones defined in the snippet):
example.com/checkout/?add-to-cart=1234&bfn=Rodolfo&bln=Melogli&bem[email protected]&bph=123456789&bco=BusinessBloomer&bcy=IT&bst=PA&ba1=viaRoma&ba2=1&bci=Palermo&bpo=90100&sfn=John&sln=Doe&sem[email protected]&sco=JDCO&scy=US&sst=CA&sa1=SunsetBoulevard&sa2=1234&sci=LosAngeles&spo=90145
2) No blank spaces are allowed in the URL e.g. “SunsetBoulevard”. If you need to generate a space e.g. “Sunset Boulevard” you need to use the encoded space character: “%20”. Untested.
3) You can omit whatever you wish in the URL, except the add to cart product ID, which is responsible for adding a product to Cart. Read this helpful guide to add simple / variable / etc. products to cart with a given quantity
4) The URL redirects to “/checkout/” – that’s the Checkout page slug. If you have edited that, change the URL accordingly
5) Countries and – in some cases – states require their 2-letter codes (“US”, “CA” for example)
6) Inside the PHP snippet, be very careful when editing the $topopulate array. Array values must match the WooCommerce checkout field IDs, otherwise it won’t populate them. You can remove any key/value from the array if you don’t need to populate whatever field e.g. Billing Phone
/**
* @snippet Populate Fields Via URL @ WooCommerce Checkout
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 6
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_filter( 'woocommerce_add_cart_item_data', 'bbloomer_save_custom_data_in_cart_object', 9999, 3 );
function bbloomer_save_custom_data_in_cart_object( $cart_item_data, $product_id, $variation_id ) {
$topopulate = array(
'bfn' => 'billing_first_name',
'bln' => 'billing_last_name',
'bem' => 'billing_email',
'bph' => 'billing_phone',
'bco' => 'billing_company',
'bcy' => 'billing_country',
'bst' => 'billing_state',
'ba1' => 'billing_address_1',
'ba2' => 'billing_address_2',
'bci' => 'billing_city',
'bpo' => 'billing_postcode',
'sfn' => 'shipping_first_name',
'sln' => 'shipping_last_name',
'sem' => 'shipping_email',
'sco' => 'shipping_company',
'scy' => 'shipping_country',
'sst' => 'shipping_state',
'sa1' => 'shipping_address_1',
'sa2' => 'shipping_address_2',
'sci' => 'shipping_city',
'spo' => 'shipping_postcode',
);
foreach ( $topopulate as $urlparam => $checkout_field ) {
if ( isset( $_GET[$urlparam] ) && ! empty( $_GET[$urlparam] ) ) {
$cart_item_data[$checkout_field] = esc_attr( $_GET[$urlparam] );
}
}
return $cart_item_data;
}
add_filter( 'woocommerce_checkout_fields' , 'bbloomer_populate_checkout', 9999 );
function bbloomer_populate_checkout( $fields ) {
$topopulate = array(
'bfn' => 'billing_first_name',
'bln' => 'billing_last_name',
'bem' => 'billing_email',
'bph' => 'billing_phone',
'bco' => 'billing_company',
'bcy' => 'billing_country',
'bst' => 'billing_state',
'ba1' => 'billing_address_1',
'ba2' => 'billing_address_2',
'bci' => 'billing_city',
'bpo' => 'billing_postcode',
'sfn' => 'shipping_first_name',
'sln' => 'shipping_last_name',
'sem' => 'shipping_email',
'sco' => 'shipping_company',
'scy' => 'shipping_country',
'sst' => 'shipping_state',
'sa1' => 'shipping_address_1',
'sa2' => 'shipping_address_2',
'sci' => 'shipping_city',
'spo' => 'shipping_postcode',
);
foreach ( WC()->cart->get_cart() as $cart_item ) {
foreach ( $topopulate as $urlparam => $checkout_field ) {
if ( isset( $cart_item[$checkout_field] ) && ! empty( $cart_item[$checkout_field] ) ) {
switch ( substr( $checkout_field, 0, 7 ) ) {
case 'billing':
$fields['billing'][$checkout_field]['default'] = $cart_item[$checkout_field];
break;
case 'shippin':
$fields['shipping'][$checkout_field]['default'] = $cart_item[$checkout_field];
break;
}
}
}
}
return $fields;
}
This works brilliantly, thank you!
Is it possible to add a custom product with a custom price directly. ie. the url parameters would have a custom product name with a custom price that creates a product ‘on the fly’ (does not need to be saved as a product for future use) that they can checkout?
The use-case is that we’d like to offer a link to checkout for quotes that we produce offline. The reason for doing this through WooCommerce and not a form with payment link is that we’d like to use Woo plugins for calculating and applying delivery costs and discounts.
Look forward to your thoughts.
Yes, some additional code would be required, but that’s possible. I’d still recommend creating a “hidden” product, and using the URL to change its checkout price programmatically, which is the easiest thing to do. Hope this helps!
Thank you for pointing me in the right direction!
We created a hidden product and were able to get a custom price to show in the checkout.
Awesome!
Great post. I did not know how to do this. I will make a slight change to address the privacy issue that you highlight.
My normal scenario is that I send a subscriber a direct mail with a links to a product and so this is very useful.
I will not put the explicit checkout field data in the URL as you have. I will put a key such as encrypted_subscriber_id in the link. I will then use your code but look-up the details. This removes the privacy issues that you highlight.
Perfect, thanks for that!