I have a website that uses WordPress and Woocommerce and i want to redirect the user to a custom URL after he do log in with the WooCommerce login page.
I’m new to programming and wordpress, sorry if my question looks dumb
I searched for the solution in the internet and found this:
function my_login_redirect( $redirect_to, $request, $user ) {
$redirect_to = 'CustomURLhere';
return $redirect_to;
}
add_filter( 'woocommerce_login_redirect', 'my_login_redirect', 10, 3 );
but it didn’t work, it gave me a message that my website have an error
2
Answers
i think you don’t need to use "$request" and "$user" for login redirection, just try to add this code at the bottom of your functions.php file:
Hope it helps !
To redirect a user to a specific page after they log in to your WooCommerce website, you can use the
woocommerce_login_redirect
filter. Here’s an example of how to use it:1. Open your website’s functions.php file (you can find it in your WordPress theme’s directory).
2. Add the following code to the file:
3. Replace /my-account/ with the URL of the page you want to redirect the user to after they log in.
4. Save the changes to the functions.php file.
Now, when a user logs in to your WooCommerce website, they will be redirected to the page you specified. Note that this code only redirects users with the "subscriber" role. You can modify the code to redirect users with different roles or to redirect all users.