Website Building » WooCommerce » How Do I Redirect a User to Another Page After Login in WooCommerce?

How Do I Redirect a User to Another Page After Login in WooCommerce?

Last updated on January 15, 2023 @ 10:18 am

After a user logs in to your WooCommerce store, you may want to redirect them to another page. For example, you might want to redirect them to their account page or the checkout page.

In this article, we’ll show you how to redirect a user to another page after login in WooCommerce.

There are two ways to redirect a user after login in WooCommerce. The first way is to use the login hook and the second way is to use the woocommerce_login_redirect filter.

To redirect a user after login using the login hook, you would need to add the following code to your theme’s functions.php file:

PRO TIP: If you are planning to redirect a user to another page after login in WooCommerce, it is important to note that this can cause issues with some plugins. Specifically, plugins that rely on the WooCommerce login process may not function properly if you are redirecting users to a different page.

Additionally, if you are using any third-party login services, they may also be affected by this change. As a result, we recommend that you test your site thoroughly after making this change to ensure that everything is still working as expected.

add_action( 'login', 'my_login_redirect' );
function my_login_redirect() {
    wp_redirect( home_url() );
    exit; }

You can replace home_url() with any other URL, such as the account page or checkout page URL. If you want to redirect users to the same page they were on before they logged in, you can use the wp_get_referer() function:

add_action( 'login', 'my_login_redirect' ); 
function my_login_redirect() { 
    $url = wp_get_referer(); 
if ( ! $url ) { 
    $url = home_url(); } 
    wp_redirect( $url ); 
exit; } 

The second way to redirect users after login is by using the WooCommerce_login_redirect filter. This filter allows you to modify the URL that a user is redirected to after logging in. You would need to add the following code to your theme’s functions.php file:

add_filter( 'woocommerce_login_redirect', 'my_login_redirect' ); 
function my_login 
Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.