in Woocommerce I need to pass from Elementor Form (by URL Redirecton) to Checkout Page with Add To Cart (of a specific ID product) and prefill fields like Name, Surname, Email and Phone

Job ID: 33671843

Budget: €8 – €30 EUR

I have a landing page with an Elementor form, in a Wordpress website with woocommerce.
When an user send the form, with input data as Name, Surname, Email and Phone, he get an add to cart (for a specific product id) and the automatic redirection to the checkout page. In the same time I need that he find automatically filled the billing fields that he already have input in the Elementor form.

[URL FOR ADD-TO-CART REDIRECTION]
I actually do the add to cart with the URL redirection in the Elementor form with:
https://mywebsite.com/checkout/?add-to-cart=49&quantity=1

[URL FOR FILL CHECKOUT FIELDS FROM URL PARAMETERS]
Also, with this url
https://mywebsite.com/checkout//checkout/?&ga_email=myemail@testemail_com&ga_name=MYNAME&ga_surname=MYSURNAME&ga_phone=222222222

But, if want to do it togheter, I can't because works only the add-to-cart when i post this URL:
https://mywebsite.com/checkout//checkout/?add-to-cart=549&quantity=1&ga_email=myemail@testemail_com&ga_name=MYNAME&ga_surname=MYSURNAME&ga_phone=222222222

---------------------------------------------
Down here the code that i've insert in functions.php to get Name, Surname, Email and Phone from the URL:
// Save user data from URL to Woocommerce session
add_action( 'template_redirect', 'set_custom_data_wc_session' );
function set_custom_data_wc_session () {
if ( isset( $_GET['ga_em'] ) || isset( $_GET['ga_nm'] ) || isset( $_GET['ga_sr'] ) || isset( $_GET['ga_ph'] ) ) {
$em = isset( $_GET['ga_em'] ) ? esc_attr( $_GET['ga_em'] ) : '';
$name = isset( $_GET['ga_nm'] ) ? esc_attr( $_GET['ga_nm'] ) : '';
$surname = isset( $_GET['ga_sr'] ) ? esc_attr( $_GET['ga_sr'] ) : '';
$phone = isset( $_GET['ga_ph'] ) ? esc_attr( $_GET['ga_ph'] ) : '';

// Set the session data
WC()->session->set( 'custom_data', array( 'email' => $em, 'name' => $name, 'surname' => $surname, 'phone' => $phone ) );
}
}

// Autofill checkout fields from user data saved in Woocommerce session
add_filter( 'woocommerce_billing_fields' , 'prefill_billing_fields' );
function prefill_billing_fields ( $address_fields ) {
// Get the session data
$data = WC()->session->get('custom_data');

// Email
if( isset($data['email']) && ! empty($data['email']) )
$address_fields['billing_email']['default'] = $data['email'];

// Name
if( isset($data['name']) && ! empty($data['name']) )
$address_fields['billing_first_name']['default'] = $data['name'];

// Surname
if( isset($data['surname']) && ! empty($data['surname']) )
$address_fields['billing_last_name']['default'] = $data['surname'];

// Phone
if( isset($data['phone']) && ! empty($data['phone']) )
$address_fields['billing_phone']['default'] = $data['phone'];

return $address_fields;
}
Related categories: PHP WordPress WooCommerce Elementor