Search the site:

Home Blog How to redirect users to another page after Login in WooCommerce

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

Leave a Reply

avatar

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

  Subscribe  
Notify of
from purchased

Subscribe Now