mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Validate new user creation
This commit is contained in:
parent
c8e492ed1e
commit
654d6d6da8
1 changed files with 39 additions and 0 deletions
|
@ -39,6 +39,45 @@ class CheckoutFormValidator extends WC_Checkout {
|
|||
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||
@$this->validate_checkout( $data, $errors );
|
||||
|
||||
if (
|
||||
apply_filters( 'woocommerce_paypal_payments_early_wc_checkout_account_creation_validation_enabled', true ) &&
|
||||
! is_user_logged_in() && ( $this->is_registration_required() || ! empty( $data['createaccount'] ) )
|
||||
) {
|
||||
$username = ! empty( $data['account_username'] ) ? $data['account_username'] : '';
|
||||
$email = $data['billing_email'] ?? '';
|
||||
|
||||
if ( email_exists( $email ) ) {
|
||||
$errors->add(
|
||||
'registration-error-email-exists',
|
||||
apply_filters(
|
||||
'woocommerce_registration_error_email_exists',
|
||||
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
||||
__( 'An account is already registered with your email address. <a href="#" class="showlogin">Please log in.</a>', 'woocommerce' ),
|
||||
$email
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $username ) { // Empty username is already checked in validate_checkout, and it can be generated.
|
||||
$username = sanitize_user( $username );
|
||||
if ( empty( $username ) || ! validate_username( $username ) ) {
|
||||
$errors->add(
|
||||
'registration-error-invalid-username',
|
||||
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
||||
__( 'Please enter a valid account username.', 'woocommerce' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( username_exists( $username ) ) {
|
||||
$errors->add(
|
||||
'registration-error-username-exists',
|
||||
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
||||
__( 'An account is already registered with that username. Please choose another.', 'woocommerce' )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $errors->has_errors() ) {
|
||||
throw new ValidationException( $errors->get_error_messages() );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue