Skip to content

Instantly share code, notes, and snippets.

@vanbo
Created October 30, 2017 20:32
Show Gist options
  • Save vanbo/01540c86271a742b6796bc0a32737749 to your computer and use it in GitHub Desktop.
Save vanbo/01540c86271a742b6796bc0a32737749 to your computer and use it in GitHub Desktop.
WooCommerce: Block admistrator from WC Login form
add_filter( 'woocommerce_login_credentials', 'prefix_check_admin_login' );
function prefix_check_admin_login( $credentials ) {
if ( is_email( $credentials['user_login'] ) ) {
$user = get_user_by( 'email', $credentials['user_login'] );
} else {
$user = get_user_by( 'login', $credentials['user_login'] );
}
// If the user is administrator or has any rights that you want
if ( user_can( $user, 'administrator' ) ) {
// Invalidate the username to symbols
$credentials['user_login'] = '-_-';
}
return $credentials;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment