I have users registering through the plugin Ultimate Member. I am trying to register a billing address for woo commerce at the same time. For the address fields I just used the meta keys for the billing address, but I don't want to do that for their first and last name and as their username is their phone number I can't do it for that one ether. I wrote this simple plugin to try and rectify the problem, but when I go to checkout their name and phone number are blank. Their address is added successfully so I know the meta keys are right. I am using update_user_meta
should I be using update_post_meta
instead? Many thanks
<?php
/*
Plugin Name: Autofill users info at checkout
*/
function autofill_users_info_at_checkout_update_meta( $user_id ) {
if ( isset( $_POST['user_login'] ) )
update_user_meta($user_id, 'billing_phone', $_POST['user_login']);
if ( isset( $_POST['first_name'] ) )
update_user_meta($user_id, 'billing_first_name', $_POST['first_name']);
if ( isset( $_POST['last_name'] ) )
update_user_meta($user_id, 'billing_last_name', $_POST['last_name']);
}
add_action( 'user_register', 'autofill_users_info_at_checkout_update_meta', 10, 1 );