I'm setting up a site with woocommerce login from frontend. I want to take the customer directly from there to registering billing address. Then I want to fill in the billing first and last names with the values registrered by user registration.
This code works, but I have to refresh the billing address page to make the name show in the fields. Why?
add_action("user_register", "pb_update_user_meta", 10, 2);
function pb_update_user_meta($user_id, $redirect_to) {
global $filled;
$user_id = get_current_user_id();
$filled = get_user_meta( $user_id, 'billing_address_1', true );
if($filled != '') {
$redirect_to = home_url() . '/my-account/';
} else {
$user_first_name = get_user_meta('first_name');
$user_last_name = get_user_meta('last_name');
// setting up billing name
update_user_meta( $user_id, 'billing_first_name', $user_first_name );
update_user_meta( $user_id, 'billing_last_name', $user_last_name );
$redirect_to = home_url() . '/my-account/edit-address/billing/';
}
return $redirect_to;
}
I have also tried the same by using woocommerce_login_redirect filter instead, but with the same result.
/my-account/edit-address/billing/?first_name=' . $user_first_name . '&last_name=' . $user_last_name
. Do not forget to escape the values to avoid XSS attacks etc.$_GET['first_name']