Skip to:
Content
Pages
Categories
Search
Top
Bottom

Redirect user role to own profile at login

Viewing 3 replies - 1 through 3 (of 3 total)

  • djmazi12
    Participant

    @djmazi12

    function wc_custom_user_redirect( $redirect, $user ) {
    // Get the first of all the roles assigned to the user
    $role = $user->roles[0];
    
    $myaccount = get_permalink( wc_get_page_id( 'myaccount' ) );
    
    if( $role == 'child' ) {
       $redirect = bp_core_get_user_domain( $user->ID );
    } 
       } else {
    //Redirect any other role to the previous visited page or, if not available, to the home
    $redirect = wp_get_referer() ? wp_get_referer() : home_url();
    }
       return $redirect;
    }
    add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );

    Gives me internal error.


    djsteveb
    Participant

    @djsteveb

    I use https://wordpress.org/plugins/buddypress-login-redirect/ – and it does exactly that.


    danbp
    Participant

    @danbp

    @djmazi12,

    the error is because you use 2 closing brackets near else. Try with only one ! And please, use the code button when you insert code into a topic…

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar