How to Add Customer Shipping Address Programmatically

Today, we are going to teach you how to create a WordPress new customer user with a shipping 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.
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.

<strong>// customer shipping address</strong>
$customerId =10;
update_user_meta( $customerId, 'shipping_email', 'shipping_email' );
update_user_meta( $customerId, 'shipping_first_name', 'shipping_first_name' );
update_user_meta( $customerId, 'shipping_last_name', 'shipping_last_name' );
update_user_meta( $customerId, 'shipping_company', 'shipping_company' );
update_user_meta( $customerId, 'shipping_address_1', 'shipping_address_1' );
update_user_meta( $customerId, 'shipping_address_2', 'shipping_address_2' );
update_user_meta( $customerId, 'shipping_city', 'shipping_city' );
update_user_meta( $customerId, 'shipping_postcode', 'shipping_postcode' );
update_user_meta( $customerId, 'shipping_country', 'shipping_country' );
update_user_meta( $customerId, 'shipping_state', 'shipping_state' );
update_user_meta( $customerId, 'shipping_phone', 'shipping_phone' );

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!