Fill checkout fields values from URL variables in Woocommerce Fill checkout fields values from URL variables in Woocommerce wordpress wordpress

Fill checkout fields values from URL variables in Woocommerce


Here below is an example with billing first name and last name based on Get url variables for checkout fields.

Its based on your Url example: checkout/?FirstName=Test&LastName=Test&EmailAddress=Test

The code:

add_filter( 'woocommerce_checkout_get_value' , 'custom_checkout_get_value', 20, 2 );function custom_checkout_get_value( $value, $imput ) {    // Billing first name    if(isset($_GET['FirstName']) && ! empty($_GET['FirstName']) && $imput == 'billing_first_name' )        $value = esc_attr( $_GET['FirstName'] );    // Billing last name    if(isset($_GET['LastName']) && ! empty($_GET['LastName']) && $imput == 'billing_last_name' )        $value = esc_attr( $_GET['LastName'] );    // Billing email    if(isset($_GET['EmailAddress']) && ! empty($_GET['EmailAddress']) && $imput == 'billing_email' )        $value = sanitize_email( $_GET['EmailAddress'] );    return $value;}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here