i'd added a hook to sync usermeta with Wc_billing_field when user update his profile
this is the code that id used to and works
add_filter( 'profile_update' , 'custom_update_checkout_fields', 10, 2 );
function custom_update_checkout_fields($user_id, $old_user_data ) {
$current_user = wp_get_current_user();
if($current_user->user_firstname != $current_user->billing_first_name)
update_user_meta($user_id, 'billing_first_name', $current_user->user_firstname);
if($current_user->user_lastname != $current_user->billing_last_name)
update_user_meta($user_id, 'billing_last_name', $current_user->user_lastname);
if($current_user->user_email != $current_user->billing_email)
update_user_meta($user_id, 'billing_email', $current_user->user_email);
if($current_user->company != $current_user->billing_company)
update_user_meta($user_id, 'billing_company', $current_user->company);
if($current_user->telefono != $current_user->billing_phone)
update_user_meta($user_id, 'billing_phone', $current_user->telefono);
if($current_user->vat != $current_user->billing_piva)
update_user_meta($user_id, 'billing_piva', $current_user->vat);
if($current_user->sdi != $current_user->billing_code_sdi)
update_user_meta($user_id, 'billing_code_sdi', $current_user->sdi);
}
I need also to reverse update from checkout to usermeta but next code update only first_name and last_name, no other fields are updated, giv me page error.
action( 'woocommerce_thankyou', 'update_usermeta_from_billing_checkout' );
function update_usermeta_from_billing_checkout( $order_id ) {
$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();
update_user_meta( $user_id, 'first_name', $order->get_billing_first_name() );
update_user_meta( $user_id, 'last_name', $order->get_billing_last_name() );
update_user_meta( $user_id, 'vat', $order->get_billing_piva() );
update_user_meta( $user_id, 'sdi', $order->get_billing_code_sdi() );
update_user_meta( $user_id, 'telefono', $order->get_billing_phone() );
}
someone can help ? thanks