1
votes

I'm trying to find a woocommerce method that will allow me to set the billing and or shipping first name.

The customer class will allow me to set some fields but not first_name. Anyone know if a method exists or do I need to just update the wp_usermeta table directly using billing_first_name.

Here is an example of what doesn't work:

global $woocommerce;

$user_first_name = get_user_meta( $user_id, 'first_name', true );

if( !empty( $woocommerce->customer->get_billing_first_name() ) ) {

    $woocommerce->customer->set_billing_first_name($user_first_name); // a set_billing_first_name method doesn't exist

}
1
Welcome to stackoverflow! It would help a lot if you posted some code, showing how you are doing it now, and/or how you want to do it in the future. What exactly is the problem? - davidkonrad
Thanks for letting me know - user8582

1 Answers

0
votes

Customer in woocommerce is nothing but a Wordpress user. If you look at WC_Checkout->process_checkout() is creates a new user and then sets billing_first_name as first_name. So to update the billing_first_name update the first_name using update_user_meta.

Hope this helps!