Woocommerce, prevent login after registration and redirect to custom URL

admin2025-01-07  8

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

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

Share Improve this question asked Mar 18, 2021 at 21:00 sebseb 11 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 3

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);

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();
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736263578a902.html

最新回复(0)