I am trying to redirect multiple users to different pages based on their
user_Id
or user_login
. but everytime when i login it takes me to the second user. How can i fix it?
For Example: When
user X
login i want to redirect to Page X
, when User Y
login i want to load page Y
the same for all users
For the First User
add_filter('woocommerce_login_redirect', 'wc_login_redirect_2nd');
function wc_login_redirect_2nd( ) {
$user_info = get_userdata(9100010);
if ($user_id == 0) {
$redirect_to = 'http://example.com/'.$user_info->user_login.'/';
return $redirect_to;
} }
for the Second user
add_filter('woocommerce_login_redirect', 'wc_login_redirect');
function wc_login_redirect( ) {
$user_info = get_userdata(9100008);
if ($user_id == 0) {
$redirect_to = 'http://example.com/'.$user_info->user_login.'/';
return $redirect_to;
} }
Answer:
You definitely don't need 2 functions. If you really need it, and I can't see yet that you do, you could simply use some conditional logic inside the function. Also notice that there are 2 variables available at the
woocommerce_login_redirect
filter that you can make use of.add_filter('woocommerce_login_redirect', 'wc_login_redirect', 10, 2);
function wc_login_redirect( $redirect, $user ) {
return 'http://example.com/'.$user_info->user_login;
}
No comments:
Post a Comment