Automattic\WooCommerce\Internal\StockNotifications\Frontend

SignupService::create_customerprivateWC 1.0

Create a new customer.

Method of the class: SignupService{}

No Hooks.

Returns

Int|null. The user ID if the customer was created, null otherwise.

Usage

// private - for code of main (parent) class only
$result = $this->create_customer( $user_email );
$user_email(string) (required)
The user email.

SignupService::create_customer() code WC 10.3.6

private function create_customer( string $user_email ) {

	if ( empty( $user_email ) || ! is_email( $user_email ) ) {
		return null;
	}

	try {
		$username = wc_create_new_customer_username( $user_email );
		$username = sanitize_user( $username );
		if ( empty( $username ) || ! validate_username( $username ) ) {
			return null;
		}

		$password = 'yes' === get_option( 'woocommerce_registration_generate_password' ) ? '' : wp_generate_password();
		$user_id  = wc_create_new_customer( $user_email, $username, $password );
		if ( is_a( $user_id, 'WP_Error' ) ) {
			return null;
		}
	} catch ( \Throwable $e ) {
		return null;
	}

	return $user_id;
}