WC_Customer_Data_Store::create()
Method to create a new customer in the database.
Method of the class: WC_Customer_Data_Store{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Customer_Data_Store = new WC_Customer_Data_Store(); $WC_Customer_Data_Store->create( $customer );
- $customer(WC_Customer) (required) (passed by reference — &)
- Customer object.
Changelog
Since 3.0.0 | Introduced. |
WC_Customer_Data_Store::create() WC Customer Data Store::create code WC 9.4.2
public function create( &$customer ) { $id = wc_create_new_customer( $customer->get_email(), $customer->get_username(), $customer->get_password() ); if ( is_wp_error( $id ) ) { throw new WC_Data_Exception( $id->get_error_code(), $id->get_error_message() ); } $customer->set_id( $id ); $this->update_user_meta( $customer ); // Prevent wp_update_user calls in the same request and customer trigger the 'Notice of Password Changed' email. $customer->set_password( '' ); wp_update_user( apply_filters( 'woocommerce_update_customer_args', array( 'ID' => $customer->get_id(), 'role' => $customer->get_role(), 'display_name' => $customer->get_display_name(), ), $customer ) ); $wp_user = new WP_User( $customer->get_id() ); $customer->set_date_created( $wp_user->user_registered ); $customer->set_date_modified( get_user_meta( $customer->get_id(), 'last_update', true ) ); $customer->save_meta_data(); $customer->apply_changes(); do_action( 'woocommerce_new_customer', $customer->get_id(), $customer ); }