I want to set the redirection for the login & signup page to my account page. If a user is already logged in & they have a customer role & tries to open the login & signup page they should be redirected to my account page. I'm using this code.
add_action( 'template_redirect', 'redirect_to_myaccount_page' );
function redirect_to_myaccount_page() {
if ( is_page('login') || is_page('signup') && is_user_logged_in() && wc_user_has_role( $user, 'customer')) {
wp_redirect( 'https://mybusinessurl.com/my-account', 301 );
exit;
}
}
But the problem is when I'm trying to access the URL (mydomain.com/login or mydomain.com/signup) as a new user it's redirecting to a my-account page. and gives me an error [ERR_TOO_MANY_REDIRECTS]. Please let me know how can I fix this?