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 after login or registration in WooCommerce, to another page.
By default, when a user logs in from the My Account page, the same page gets reloaded:
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) { $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:
In this way, you can redirect the user to any page after they login.
Redirect Users to a Specific Page After Registration in WooCommerce
A well-planned redirection that too after registration can help users navigate your website more efficiently. This code snippet lets store owners to redirect users to shop page after registration in WooCommerce.
add_filter( 'woocommerce_registration_redirect', 'ts_custom_redirection_after_registration', 10, 1 ); function ts_custom_redirection_after_registration( $redirection_url ){ // Change the redirection Url $redirection_url = get_permalink( wc_get_page_id( 'shop' ) ); return $redirection_url; // Always return something }
This to the shop owners who are running or planning to run BOGO offers on their WooCommerce store…
BOGO deals are great for increasing your sales, but have you thought about which offers are bringing you more revenue and which offers are not performing that great?
Don’t just set a BOGO deal, track the revenue generated by your deals in real-time with the Flexi BOGO for WooCommerce plugin.
In the above code snippet we have used the shop page URL to get redirected to after the user registration process is done. But you can redirect to any other page as well based on your unique business needs. I will provide some other common Redirection URL’S
used in woocommerce:
- Get the “Home” page Url: $redirection_url = get_home_url();
- Get the “Shop” page url: $redirection_url = get_permalink( wc_get_page_id( ‘shop’ ) );
- Get the “Cart” page Url: $redirection_url = wc_get_cart_url();
- Get the “Checkout” page Url: $redirection_url = wc_get_checkout_url();
Output
The below output video shows that once the user completes the registration process, the user is redirected to the shop page.
To make the checkout process faster, you can also try redirection at different spots on your website. Refer to this guide to make your WooCommerce add to cart button redirect to checkout page.
Where is Registration redirection,
Are you here to just get the user count on the page,
You should remove/update the title if you don’t have the full solution.
Login redirection part is correct but if someone is looking for redirection after registration, will not get the answer on this page
Hi Rajat,
I apologize for the inconvenience. Previously, we recommended the “WooCommerce Login Redirect” plugin for redirecting users after registration. However, since the plugin has not been updated and tested with the latest releases of WordPress, we removed it from the post. The post has been updated & please refer to the code snippet below the title ‘Redirect Users to a Specific Page After Registration in WooCommerce’.
I just tried this code, and no matter what permalink I set for the redirect, the redirect only goes to the homepage. I removed the code, and it goes back to the normal Woo function of going to my-account. Any ideas?
im getting this in the debug log
PHP Fatal error: Uncaught Error: Value of type float is not callable
i put the code into my child theme and changed the word shop to my shops url but it still goes to my account page
This plugin doesn’t work!
Sorry, that plugin had not been updated in 3 years. I have now removed it from this article and also edited the code snippet.