Table of Contents
Customized redirection after login
What a pity, isn’t it? That a customer accesses your online store and by default is still on the page of your user account. I mean, I’m not saying that he doesn’t have interesting things to do there, like changing his data, adding payment methods and even checking the orders, but wouldn’t it be better that, since he has accessed your store, and your store sells things, and possibly has logged in to buy something, you redirect him to a page where he can buy something?
I propose you to redirect him to the home page, thanks to this simple code:
/* Redirect clients to the store after login in */
add_filter( 'woocommerce_login_redirect', 'wphelp_redirect_login_store', 9999 );
function wphelp_redirect_login_store( $redirect_url ) {
$redirect_url = '/shop';
return $redirect_url;
}
Code language: PHP (php)
If you prefer to redirect to another page of your site simply change the slug in the $redirect_url line.
Personalized redirection after registration
And what do we do with new customers as soon as they sign up? Do we leave them there on their account page so they know they have it?
It’s not a bad option either, but I’m sure you can think of a better place to send them right after they sign up to your online store. I suggest you create a welcome page with the latest offers, even shopping tips.
Just create it and remember the slug then add something like this.
/* Redirect clients to the store after registration */
add_filter( 'woocommerce_registration_redirect', 'wphelp_redirect_registration' );
function wphelp_redirect_registration( $redirect_url ) {
$redirect_url = '/registrationhome';
return $redirect_url;
}
Code language: PHP (php)
How and where do I add these functions?
Here is a quick and easy guide to the different methods, for all audiences, with which you can add codes to your website…
How and where to paste PHP, JS, CSS codes and functions you find around in WordPress