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.