Wordpress / Woocommerce: disable Login Redirection URL on checkout

Hello! We use the Auth0 Wordpress Login Plugin. We set the Login Redirection URL in Advanced Settings to /cart/ because we want customers who login on checkout to stay there. But that also redirects users who use the my account login avatar of woocommerce.

We need to change the redirct_to after login on checkout to stay, but it is not possible to leave Login Redirection URL empty and let wordpress decide where to redirect.

Problem solved. After switching from Embedded Login form to Universal Login Page (ULP) the Login Redirection URL in Advanced Settings is ignored on checkout and login to the “My Account” page works without redirecting to checkout.

On functions.php file or create a custom plugin file.
Add the following code to override the login redirection specifically for the checkout page:


/**
 * Modify the login redirect for the checkout page.
 *
 * @param string $redirect_to The default redirect URL.
 * @param string $request The login request.
 * @param WP_User $user The user object.
 * @return string The modified redirect URL.
 */
function custom_checkout_login_redirect( $redirect_to, $request, $user ) {
    // Check if the login is happening on the checkout page
    if ( function_exists( 'is_checkout' ) && is_checkout() ) {
        // Modify the redirect URL as per your requirement
        $redirect_to = ''; // Set it to empty or the desired URL on the checkout page
    }
    return $redirect_to;
}
add_filter( 'login_redirect', 'custom_checkout_login_redirect', 10, 3 );

This code overrides the login redirect behavior specifically for the checkout page. By setting the “$redirect_to” value to an empty string or the desired URL, you can control where the user stays after logging in during the checkout process.