Is there anyway to create a customer programmatically like you can with a WordPress user. Obviously the WooCommerce user shares some of the same WordPress user fields, there there is additional content that would need to be set like Billing / Postal address.
Has anyone achieved this before? I can’t find anything in the WooCommerce API / functions list on their website.
EDIT: Just found this: http://docs.woothemes.com/wc-apidocs/function-wc_create_new_customer.html
But how can I then provide other field details (like addresses).
WooCommerce customer is essentially a WordPress user with extra metadata. So once the user is created you can add metadata to it by using
update_user_meta
function. Navigate to Users -> All Users, edit one of the users and then scroll down to see the fields.Made up code given below to give you the gist of how it works.
Here is the full list of billing and shipping fields
Billing
Shipping
Before attempting to create a new user I see if that user already exists and update the existing user if found. the get_user_by(field,value) function returns the user object so if the user exists use their id to update meta fields or if not create a new one.