Reputation: 671
I'm currently using WooCommerce.
To make life easy for my customers I've got rid of the 'First Name' and 'Last Name' fields on the Account Registration. I've just got the email address.
However, when the customer checks out I'd like to populate the 'user_firstname' with the 'billing_first_name' value in their user meta.
I'm trying the following code but doesn't seem to work - any ideas?
// Auto Update User Details
add_filter( 'process_checkout' , 'custom_update_checkout_fields', 10, 2 );
function custom_update_checkout_fields($user_id, $old_user_data ) {
$current_user = wp_get_current_user();
// Updating Billing info
if($current_user->billing_first_name != $current_user->user_firstname)
update_user_meta($user_id, 'user_firstname', $current_user->billing_first_name);
}
Cheers,
Linz
Upvotes: 0
Views: 6197
Reputation: 671
Ok, so I found a good solution:
add_action('woocommerce_checkout_order_processed', 'custom_process_order1', 10, 1);
function custom_process_order1($order_id) {
$current_user = wp_get_current_user();
$current_user_id = get_current_user_id();
update_user_meta($current_user_id, "first_name", $current_user->billing_first_name);
update_user_meta($current_user_id, "last_name", $current_user->billing_last_name);
}
I'm a bit of a newb, so help others out.
Hope that helps any readers.
Upvotes: 1