• Resolved jimishsoni1990

    (@jimishsoni1990)


    Hi, can you please pass the “$user_signon” variable to “wcalr_login_redirect” filter, so we can redirect user based on who has logged in, like different roles, or different capabilities.

    its on the line number 229, in woocommerce-ajax-login-register.php file.

    just change this line:

    'redirect' => apply_filters( "wcalr_login_redirect", false)

    to this:

    'redirect' => apply_filters( "wcalr_login_redirect", false, $user_signon)

    Hope that helps. thank you for this amazing plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Zorem

    (@zorem)

    Hi @jimishsoni1990,

    Ok we will add the “$user_signon” variable to the “wcalr_login_redirect” filter in the next version of the plugin.

    Thanks,

    @jimishsoni1990

    By user roles with combination with referer url, we are using something like:

    // start global session for saving the referer url
    function wcalr_ref_session() {
        if(!session_id()) {
            session_start();
        }
    }
    add_action('init', 'wcalr_ref_session');
    
    // get referer url and save it 
    function wcalr_redirect_url() {
        if ( !is_user_logged_in() && !is_checkout() ) {
            $_SESSION['referer_url'] = $_SERVER['HTTP_REFERER'];
        }
        // Exclude Checkout page
        elseif ( !is_user_logged_in() && is_checkout() ) {
            $_SESSION['referer_url'] = '/payment';
        } 
        else {
            if(session_id()){
                session_destroy();
            }
        }
    }
    add_action( 'template_redirect', 'wcalr_redirect_url' );
    
    // redirect after LOGIN
    add_filter( "wcalr_login_redirect", "wcalr_login_redirect_link", 10, 1);
    function wcalr_login_redirect_link($link){
        $link = $_SESSION['referer_url'];
        if(current_user_can('administrator')) {
            $link = admin_url();
        }
        /**** ... ***/
        return $link;
    }
    Thread Starter jimishsoni1990

    (@jimishsoni1990)

    Hi @rkoms

    Thanks for the solution, but to be honest its overkill solution to easy problem. If he just adds that parameter to filter, it will help us to make many other conditional redirections.

    Thread Starter jimishsoni1990

    (@jimishsoni1990)

    Hi @zorem ,

    Can you please let us know any ETA for this.

    Thanks mate.

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

The topic ‘Redirect based on user role.’ is closed to new replies.