Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

wc php after login redirect page

// start global session for saving the referer url
function start_session() {
    if(!session_id()) {
        session_start();
    }
}
add_action('init', 'start_session', 1);

// get  referer url and save it 
function redirect_url() {
    if (! is_user_logged_in()) {
        $_SESSION['referer_url'] = wp_get_referer();
    } else {
        session_destroy();
    }
}
add_action( 'template_redirect', 'redirect_url' );

//login redirect 
function login_redirect() {
    if (isset($_SESSION['referer_url'])) {
        wp_redirect($_SESSION['referer_url']);
    } else {
        wp_redirect(home_url());
    }
}
add_filter('woocommerce_login_redirect', 'login_redirect', 1100, 2);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #wc #php #login #redirect #page
ADD COMMENT
Topic
Name
4+3 =