How to Add WooCommerce Customer Billing Address Programmatically
Today, we are going to teach you how to create a WooCommerce user billing address programmatically using either the wp_create_user() or wp_insert_user() functions. In this tutorial, we will show you the difference between them and look through some examples as well.
Difference Between wp_create_user() and wp_insert_user().
These functions will only allow you to provide a username, password, and email when creating a user. A user will be created with a default role, which is set in Settings > General .
You can change this value in settings.
More than that, wp_create_user() works on the base of wp_insert_user().
It is a complete way of creating a WordPress customer user programmatically. You can provide other useful data, such as first and last names, a display name, a user role, and so on.
$customerId =10;
update_user_meta( $customerId, 'billing_email', 'billing_email' );
update_user_meta( $customerId, 'billing_first_name', 'billing_first_name' );
update_user_meta( $customerId, 'billing_last_name', 'billing_last_name' );
update_user_meta( $customerId, 'billing_company', 'billing_company' );
update_user_meta( $customerId, 'billing_address_1', 'billing_address_1' );
update_user_meta( $customerId, 'billing_address_2', 'billing_address_2' );
update_user_meta( $customerId, 'billing_city', 'billing_city' );
update_user_meta( $customerId, 'billing_postcode', 'billing_postcode' );
update_user_meta( $customerId, 'billing_country', 'billing_country' );
update_user_meta( $customerId, 'billing_state', 'billing_state' );
update_user_meta( $customerId, 'billing_phone', 'billing_phone' );