Search the site:

How to redirect users to another page after Login in WooCommerce

One of the unsaid rules of e-commerce sales and designing for e-commerce is to build conditions such that the user spends more time on the store, either to browse products or to shop. One such condition can be to redirect the user to the shop page as soon as they login or create an account, so that the likelihood of them seeing products that they like or wish to buy increases as a consequence. Let’s explore through this post how to redirect users to another page after Login in WooCommerce.

There are two ways of achieving this viz. a code snippet and a plugin.

By default, when a user logs in from the My Account page, the same page gets reloaded:

How to redirect users to another page after Login in WooCommerce - Default page behaviour after Login

 

Using a code snippet to redirect users to another page after Login in WooCommerce

Add the following code to the functions.php file of your child theme:

function ts_redirect_login( $redirect, $user ) {

    $redirect_page_id = url_to_postid( $redirect );
    $checkout_page_id = wc_get_page_id( 'checkout' );
    
    if( $redirect_page_id == $checkout_page_id ) {
        return $redirect;
    }
 
    return wc_get_page_permalink( 'shop' );
}
 
add_filter( 'woocommerce_login_redirect', 'ts_redirect_login' );

We use the woocommerce_login_redirect hook to achieve this. Through the code above, the user is being redirected to the Shop page after login, only if they aren’t on the Checkout page. In other words, if they login while checking out, they won’t be redirected to the Shop page. This condition has been added so that the payment process of the user is smooth, and to decrease the chances of losing the sale. Assigning the ‘shop’  value (where ‘shop’ is a relative URL that points to the store) redirects the user to the store, this can be replaced with any URL.

Using this code, the user will be redirected to the store after logging in anywhere other than on the Checkout page:

How to redirect users to another page after Login in WooCommerce - Redirection after Login

 

In this way, you can redirect the user to any page after they login. If you don’t want to use a code snippet, you can use a plugin to do the same.

Using a plugin to redirect users to another page after Login or Registration in WooCommerce

WooCommerce Login Redirect: This is a free plugin that lets you redirect users to another page within your website after login or even after registration via a simple interface. In order to redirect them to a custom URL however, you will need to purchase the premium version of this plugin. The free version also does not include conditions such as not redirecting the user to a different page if they are on the Checkout page when they login or register.

How to redirect users to another page after Login in WooCommerce - Plugin for Redirection after Registration

How to redirect users to another page after Login in WooCommerce - Plugin for Redirection after Login

 

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

6 Comments
Oldest
Newest
Inline Feedbacks
View all comments
God'swill Kalu
God'swill Kalu
2 years ago

This code is not working right, when I used it it shows “this site is experience technical difficulties” what can I do to solve this?

I used it by adding the code to a child theme functions.php file

Steven Hogenbosch
Steven Hogenbosch
2 years ago
Reply to  God'swill Kalu

I had the same experience after adding it to a child theme functions.php file: it only shows “this site is experiencing technical difficulties”
Probably something to do with the latest WP/Woo updates…

person
person
2 years ago

just remove the second parameter ($user) from the function and it will work

Arturs Gabliks
Arturs Gabliks
10 months ago

Not Working

The snippet has been deactivated due to an error on line 2:

Cannot redeclare function ts_redirect_login.

Arturs Gabliks
Arturs Gabliks
10 months ago
Reply to  Arturs Gabliks

Oh Sorry it because duplicate

Arturs Gabliks
Arturs Gabliks
10 months ago
Reply to  Arturs Gabliks

But it redirects me to Shop page anyway

from purchased

Subscribe for more offers

Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins and 50% OFF on Bundles
6
0
Would love your thoughts, please comment.x
()
x