Hi @mairh93,
Please try the following code snippet on your site to redirect after login according to the roles.
add_filter( 'user_registration_login_redirect', function( $redirect_url, $current_user ) {
$current_user = (object) $current_user;
$roles = isset( $current_user->roles ) ? (array) $current_user->roles : array();
if ( in_array( 'subscriber', $roles, true ) ) {
$redirect_url = 'https://subscribers-come-here.com';
}
if ( in_array( 'customer', $roles, true ) ) {
$redirect_url = 'https://customers-come-here.com';
}
return $redirect_url;
}, 10, 2 );
Regards!
Thank you for your time..It doenst work. After the log in I see the front page and not the page that I put in the url
View post on imgur.com
-
This reply was modified 4 years ago by
mairh93.
Hi @mairh93,
We have tested the code properly and sent it to you. Please let us with which user role you have tried to login.
Suggestion: Register one new user as a customer using the user registration form and try to login into your site after registration.
Regards!
So when I log in as Store Vendor it works, as after log in I see the /store-manager page.
But, when I log in as a customer, after the log in I continue to be in the /my-account page : image below
View post on imgur.com
Thank you!
-
This reply was modified 4 years ago by
mairh93.
Hi @mairh93,
We tested the code multiple times but did not find any issue. Could you please try a different URL for customer role redirection?
Regards!
Hello,
So after investigation, I think that the problem is in the code snippet plug in..I will check why it doesn’t work and I will try to check again your code.
Thank you for your time!
Hello,
I have one question…the code that you provided to me works after the default use registration form ? or I need to create a custom one ?
Thank you!
Hi @mairh93,
The provided codes work based on the user role, so you do not need to create a new registration form.
We will mark this thread as resolved. If you need assistance with the user registration, please create a new ticket. We will get back to you as soon as possible.
Also, if you have a moment to spare, we would appreciate your reviewing our plugin. Please click on this link https://ww.wp.xz.cn/support/plugin/user-registration/reviews and share your thoughts about our team and our plugin. We would love to hear from you.
Thanks!
Hello,
Unfortunaltely the php code dont work in my case for rederecting the user. I thought that the problem was with the Code snippet plug in, but I put directly your code in the function.php and nothing happens…the user continue to go to the /my-account page after the log in and not in the home page as I wanted.
Hi @mairh93,
It might be a conflict, or you have already set redirection for customers, so it is not working for you. Please check this documentation link https://docs.wpeverest.com/user-registration/docs/how-to-check-plugin-theme-conflict/ and follow the instruction kindly. This will let you know the cause of the error.
Let me know if it helps, and I will get back to you.
Regards!