Skip to content

Commit 0d60a4c

Browse files
authored
Merge pull request #214 from saleebm/feature/opt-password-register-customer
allow optional password creation for registerCustomer
2 parents 411a27e + 37b84fd commit 0d60a4c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

includes/mutation/class-customer-register.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ public static function mutate_and_get_payload() {
9999
if ( empty( $input['email'] ) ) {
100100
throw new UserError( __( 'Please provide a valid email address.', 'wp-graphql-woocommerce' ) );
101101
}
102-
if ( empty( $input['password'] ) ) {
103-
throw new UserError( __( 'Please enter an account password.', 'wp-graphql-woocommerce' ) );
102+
103+
// Validate password input.
104+
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && empty( $input['password'] ) ) {
105+
throw new UserError(
106+
__(
107+
'A password was not provided and WooCommerce does not automatically generate one for you.',
108+
'wp-graphql-woocommerce'
109+
)
110+
);
104111
}
105112

106113
// Map all of the args from GQL to WP friendly.
@@ -110,7 +117,7 @@ public static function mutate_and_get_payload() {
110117
$user_id = wc_create_new_customer(
111118
$user_args['user_email'],
112119
$user_args['user_login'],
113-
$user_args['user_pass'],
120+
isset($user_args['user_pass']) ? $user_args['user_pass'] : '',
114121
$user_args
115122
);
116123

0 commit comments

Comments
 (0)