0

I'm looking for a way to prevent the automatic login after registration (i.e. by logging him out after registration) and redirect him to a custom URL. So far I'm only able to do both of them individually, but the combination of it is not working. For redirect after registration I'm using the following:

    add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 );
    function custom_redirection_after_registration( $redirection_url ){
        // Change the redirection Url
        $redirection_url = "https://...";
        return $redirection_url; 
    }

When including the wp_logout() function within the function above, I think that the redirect after logout is being triggered. If that assumption is correct, I unfortunately don't know how I can redirect only that logout that's being triggered directly after the registration.

I hope that anyone can help me out? It's greatly appreciated! Best regards

2

Try this, It may helpful.

function wc_custom_registration_redirect() {
    wp_logout();
    wp_destroy_current_session();
    return home_url('/');
}
add_action('woocommerce_registration_redirect', 'wc_custom_registration_redirect', 99);
0

Whoever has also the same question as I had: This is how I got it to work:

add_filter('woocommerce_registration_redirect', 'custom_redirection_after_registration', 1);

function custom_redirection_after_registration( $redirection_url ){
    // Change the redirection Url
    add_action('wp_logout','only_redirect_unverfied_users_after_registration',1);
    wp_logout();
    wp_destroy_current_session();
    $redirection_url = "https://...";
    return $redirection_url;
}



function only_redirect_unverfied_users_after_registration(){
    $redirection_url = "https://";
    wp_redirect( $redirection_url);
    exit();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.