• Anyone know how to redirect a user login to the users personal pages. Redirect by per users?
    Basically I have users with “personal private” pages and each time they log in I want them to be able to be redirected to their “personal page”.

    Currently I see that woocommerce only has the option to allow redirections to ONE page.
    For example: User A,B,C,D,… logs in gets redirected to “about us page” (or whateve i set it too)

    But I want User A to log in and redirected to page /User-A/
    User B –> /User-B/
    and so on

    Any tips ?

    * I did download a plug in “login/logout redirects” it did work like I wanted to HOWEVER, in the menu bar once I logged in as User A and browsed the rest of the website (visitng other pages like about us, product, ect) I cant go back to the USER A “private page” as its not in the menu bar… UNLESS I create a menu bar speciically for EACH USER and assign it to their page after they log in..
    Hope its not to confusing!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You may want to try a custom statement in your themes functions.php file.

    Something like this except call the username instead of the first name, also you may not need it to be an if statement but this is the best example I can find for you that is close to what you might be looking for.

    function my_login_redirect($redirect_to, $request, $user){
        if($user->first_name == 'student')) {
            return home_url("/students/");
        } else {
            if(in_array('administrator', $user->roles)){
                return home_url("/wp-admin/");
            } else {
                return home_url();
            }
        }
    }
    add_filter("login_redirect", "my_login_redirect", 10, 3);
    Thread Starter imimike

    (@imimike)

    Thanks @binarywc for the reply! Would I have to use this code for EACH user?
    And dumb question but If the username is “Test” I would replace first_name with “test?

    Or replace the /students/ with “Test”?

    No, you should be able to modify it a but and have it look at the user who is logged in and go to their page.

    By doing that you actually wont need the first_name==’student’ part of the code I provided. What you will end up with is close to what I provided above though. Unfortunately, without access to test it would be near impossible for me to recreate the same setup you have quickly and provide correct code for exactly what you need.

    This might be closer to what you need actually.

    <?php if ( ! is_admin() ) {
    return home_url($current_user->user_login);
    } else {
    }
    ?>

    I am not sure if this will work directly but it is very close to what I think you need. It will pull the current users login and send them to their page based on their login it assumes that the pages are named the same as their username though.

    Thread Starter imimike

    (@imimike)

    :s unfortunately its not work. Its still not redirecting the login to their “account” page

    Alternatively I can still use the login function with the login/logout redirection plug in… but the problem is once a user is logged in and they browse other pages they cant really return to their private page. Because i cant physically put a menu link of their page onto the menu… I dont know if theres any way around that?

    That is not the exact code you will need, it is only close to the code you will need. As I stated earlier, I can not test it without having a setup that is exactly the same as yours. This is something I do not have.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Log In Redirect with Woocommerce’ is closed to new replies.