This is a query based around WooCommerce Membership and Subscriptions.
I must add that I'm also trying to decide if it's good UX to do what I'm doing.
There's many solutions to redirecting users after they login but I have a situation where I want to redirect a user with a role of 'subscriber' when they click on specific links to pages that describe and allow you to become a member. So although I don't want to hide 'join now' etc I just want those to redirect to the my-account page.
Again there are various roles and redirect plugins but none seem to help in this specific scenario. So the source of the code I've used is here: SOURCE and I'm looking to do something like this:
function eks_redirect_users_by_role() {
global $post;
$current_user = wp_get_current_user();
$role_name = $current_user->roles[0];
if ( 'subscriber' === $role_name && $post->ID == 47145) {
wp_redirect( '/my-account' );
}
}
add_action( 'admin_init', 'eks_redirect_users_by_rol
e' );
So if the user role is subscriber and they try and visit the page idea it's redirected.
At the current time it does fall back to a product page which says 'you already have a membership' but it's multiple steps to arrive.