Paid Memberships Pro: Restrict Checkout to Certain Email Domains
Only lets people check out with an email address from your allowed domains, for company, school or association memberships.
Opens WPIDE on
Code
if ( ! function_exists( 'pmpro_setMessage' ) ) {
return;
}
$wpide_pmpro_allowed_domains = array( 'example.com' );
add_filter( 'pmpro_registration_checks', function ( $continue ) use ( $wpide_pmpro_allowed_domains ) {
if ( ! $continue ) {
return $continue;
}
$email = is_user_logged_in() ? wp_get_current_user()->user_email : ( isset( $_REQUEST['bemail'] ) ? sanitize_email( wp_unslash( $_REQUEST['bemail'] ) ) : '' );
$domain = strtolower( substr( strrchr( $email, '@' ), 1 ) );
if ( in_array( $domain, $wpide_pmpro_allowed_domains, true ) ) {
return $continue;
}
pmpro_setMessage( sprintf( 'Please use your %s email address to join.', implode( ' or ', $wpide_pmpro_allowed_domains ) ), 'pmpro_error' );
return false;
} );
Notes
Existing members checking out while logged in are checked against their account email.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.