This topic has 7 replies, 2 voices, and was last updated 9 years by ScotKinney.

  • Author
  • #65898
     ScotKinney
    Participant

    I need to use the woocommerce login page for a separate desktop app we made. I can’t seem to find the code to redirect them to their own profile page after logging in. I also want already logged in users to go their profile when they open the app. The app uses awesomium which is similar Chrome so anything that works in Chrome will work here. I need to know what to put in place of ?user=username because it doesn’t work.
    Peter’s redirect doesn’t work for this either.

    COPY CODE
    // redirect to profile instead
    
    function scot_wc_login_redirect( $redirect ) {
         $redirect = 'http://www.alterverse.com/members/?user=username/';
         return $redirect;
    }
    add_filter('woocommerce_login_redirect', 'scot_wc_login_redirect');

    Thanks!
    Scot

    #65900
     sharmstr
    Moderator

    1 – Have you tried Peters Login Redirect plugin? It has the username variable. See attached.

    2 – BP has functions that will return that for you. bp_loggedin_user_domain is one of them. https://codex.buddypress.org/developer/playing-with-the-users-id-in-different-contexts/

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    Attachments:
    You must be logged in to view attached files.
    #65909
     ScotKinney
    Participant

    From what I understand Peter’s redirect doesn’t currently work for this: https://wordpress.org/support/topic/stopped-working-for-profile-page. I installed it and set it and it just directed me to the regular woocommerce account page.
    So, you don’t know anything I can place in the spot there that says ?user=username
    It seems like there should be something yet I’ve spent most of the day looking and no one seems to have a simple answer.

    #65913
     sharmstr
    Moderator

    I use it. That screen shot was from my site. It works. Did you try it without your scot_wc_login_redirect function active?

    Why do you have ‘?user=username’? Even if you were able to resolve ‘username’, your redirect would send them to /members/?user=sharmstr. That’s not valid.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #65914
     sharmstr
    Moderator

    Look at what this produces

    COPY CODE
    
    add_action('init','show_profile_url');
    function show_profile_url() {
        echo  bp_core_get_user_domain( get_current_user_id() );
    }
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #65918
     ScotKinney
    Participant

    Thanks man, but I’m not a coder, that’s why I’m using WordPress and BuddyPress and this theme…lol
    I just used that user=username bit as a placeholder so you could see the total url.
    But yes, I disabled my function first. Peter’s login redirect doesn’t hook into the woocommerce_login_redirect.

    The code you posted above is really greek to me. I have no idea where to put it or how to use it.
    As I understand it the username is dynamic so somehow I have to get the woocommerce logi redirect to pull it form somewhere but I have no idea how. You’d have to be completely specific, step by step.

    I also want to add some code so that if the user still is logged in via cookies the next time he comes to the page it redirects him to his profile too if you know how to do that.
    Any help is appreciated!

    #65923
     sharmstr
    Moderator

    try this code instead of yours.

    COPY CODE
    
    add_filter('woocommerce_login_redirect', 'wcs_login_redirect');
    function wcs_login_redirect( $redirect ) {
        $redirect = 'http://www.alterverse.com/wp-content/plugins/peters-login-redirect/wplogin_redirect_control.php';
        return $redirect;
    }
    

    Then go into peters redirect settings and add this to the “all other users”

    COPY CODE
    
    http://www.alterverse.com/members/[variable]username[/variable]
    

    I’ve tested it with my woo login form on the checkout page and it works.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #66062
     ScotKinney
    Participant

    This seems to do the trick:

    COPY CODE
    // Custom redirect for users after logging in with Woocommerce MyAccount page - (Scot)
    // redirect to profile instead
    function scot_wc_login_redirect( $redirect, $user ) {
    	$redirect = bp_core_get_user_domain($user->ID);
    	return $redirect;
    }
    add_filter('woocommerce_login_redirect', 'scot_wc_login_redirect', 11, 2);
Viewing 8 posts - 1 through 8 (of 8 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?