Hello to all, welcome to therichpost.com. In this post, I will tell you, Woocommerce hook to redirect user after login based on users.
I am redirecting different users to different pages after woocommerce login based on usernames.
Here is the working code for Woocommerce hook to redirect user after login based on users and you need to add this code into your theme’s functions.php file:
function wc_custom_user_redirect( $redirect, $user ) { // Get user name $username = $user->user_login; // Conditions switch ( $username ) { case 'admin': $redirect = get_permalink( get_page_by_path( 'sample-page' ) ); break; case 'username1': $redirect = get_permalink( get_page_by_path( 'sample-page-2' ) ); break; case 'username2': $redirect = get_permalink( get_page_by_path( 'sample-page-3' ) ); break; case 'username3': $redirect = get_permalink( get_page_by_path( 'sample-page-4' ) ); break; default: $redirect = wp_get_referer() ? wp_get_referer() : home_url(); } return $redirect; } add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );
If you have any query related to this post, then please comment or email me.
Recent Comments