Restrict Registration To Pre Approved User Emails Only

This code enables you to restrict registration to specific email addresses for pre approved customers only in WooCommerce. If they’re not on the list, registration page returns an error notice like this :

Registrations for WooCommerce customers are made on the example.com/my-account page.

The register field will only display if WooCommerce > Settings > Accounts & Privacy have been enabled to Allow customers to create an account on the “My account” page like this :

Once this is done, you can use code like this in your child themes functions file to control who can register.


// Add Comma Separated emails
function get_pre_approved_emails() {

    return array(
        'approved@wpsites.net',
       
    );
}

add_filter('woocommerce_registration_errors', 'restrict_registration_to_pre_approved_users', 10, 3);
function restrict_registration_to_pre_approved_users($errors, $username, $email) {

    $pre_approved_emails = get_pre_approved_emails();
    
    if ( ! in_array($email, $pre_approved_emails)) {
        
        $errors->add('registration_error', __('Registration is restricted to pre-approved users only.', 'woocommerce'));
    }
    
    return $errors;
}

You can also extend the code further so :

  • only pre approved registered users can purchase specific products.
  • registration fields are marked as compulsory
  • email addresses can be added to a custom field in your WordPress dashboard rather than pasted into the PHP code directly.

Related Coded Solutions

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.