Tagged: redirect login, woocommerce, woocommerce login
-
AuthorPosts
-
July 13, 2024 at 6:46 pm #1461991
hi
I need the login page for my woocommerce to redirect to another page after login instead of to the default “my account” page.
I am using the [woocommerce_my_account] shortcode on the page (*see private content).
Is there a way to redirect this through css or do I have to add a function?thanks for your help
NancyJuly 13, 2024 at 8:43 pm #1461996Hey Munford,
You will need to use a function, I have not done this before but I found this code to add to the end of your child theme functions.php file in Appearance ▸ Editor:function custom_redirect_after_login( $redirect, $user ) { // Check if the user is logging in from the WooCommerce login form $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; if ( empty( $requested_redirect_to ) && ( is_account_page() || is_page( 'your-login-page-slug' ) ) ) { // URL of your custom My Account page $custom_account_page_url = site_url( '/custom-my-account/' ); $redirect = $custom_account_page_url; } return $redirect; } add_filter( 'woocommerce_login_redirect', 'custom_redirect_after_login', 10, 2 );
then Replace ‘your-login-page-slug’ with the slug of your WooCommerce login page.
Replace ‘/custom-my-account/’ with the slug of your new custom My Account page.Best regards,
MikeJuly 14, 2024 at 1:17 pm #1462018thanks,
I need to get access to the site files since I’m missing the theme editor.July 14, 2024 at 1:47 pm #1462021Hi,
That could be due to a plugin like Wordfence Security or a code snippet in your wp-config.php file:define( 'DISALLOW_FILE_EDIT', true ); define( 'DISALLOW_FILE_MODS', true );
if you see this remove it.
Otherwise use FTPBest regards,
MikeJuly 22, 2024 at 7:30 pm #1462693hi MIke
Is this correct? it did not work for me. It’s still landing on the same page after login.function custom_redirect_after_login( $redirect, $user ) { // Check if the user is logging in from the WooCommerce login form $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; if ( empty( $requested_redirect_to ) && ( is_account_page() || is_page( 'https://www.wift.nu/for-medlemmer/' ) ) ) { // URL of your custom My Account page $custom_account_page_url = site_url( '/https://www.wift.nu/dashboard/' ); $redirect = $custom_account_page_url; } return $redirect; } add_filter( 'woocommerce_login_redirect', 'custom_redirect_after_login', 10, 2 );
- This reply was modified 3 months, 3 weeks ago by Munford.
July 22, 2024 at 10:22 pm #1462713Hi,
It looks like you are adding the full URL with a leading backslash before it, try using only the page URL like this:function custom_redirect_after_login( $redirect, $user ) { // Check if the user is logging in from the WooCommerce login form $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; if ( empty( $requested_redirect_to ) && ( is_account_page() || is_page( 'for-medlemmer' ) ) ) { // URL of your custom My Account page $custom_account_page_url = site_url( '/dashboard/' ); $redirect = $custom_account_page_url; } return $redirect; } add_filter( 'woocommerce_login_redirect', 'custom_redirect_after_login', 10, 2 );
Best regards,
MikeJuly 22, 2024 at 10:33 pm #1462715Hi
Thanks
I tried that but it’s still leading to the “for medlemmer” page, just logged in.July 22, 2024 at 10:43 pm #1462717Hi,
Above you linked to /bliv-medlem/, not /dashboard/ perhaps that is the issue?Best regards,
MikeJuly 22, 2024 at 10:54 pm #1462719no I had a redirect rule on there but now it’s disables and it’s still not going to the /dashboard/
July 22, 2024 at 11:31 pm #1462721Hi,
Ok please leave that disabled, and include a admin login so we can adjust the code and a client login so we can test.
Please note that I don’t think you can test with a admin login, it should be a client level login.Best regards,
MikeJuly 23, 2024 at 12:16 am #1462723is there a kriesi email I can use?
July 23, 2024 at 5:48 pm #1462781Hi,
Not one that we have access to, just use any fake one and posted the login details for both accounts in the Private Content area below.Best regards,
MikeJuly 23, 2024 at 6:13 pm #1462784This reply has been marked as private.July 23, 2024 at 11:24 pm #1462802Hi,
Thanks, when I try to go to the /for-medlemmer/ page as the client I see a 404 error, I find that the page has not been published.
For this to work the page needs to be published, it looks like you have two of these pages, so please publish and try again as a client that is not already logined in, such as in incognito mode. If it still doesn’t work I will check and try to find a solution.Best regards,
MikeJuly 23, 2024 at 11:53 pm #1462803sorry they are both published now.
When I tried before to login as a client they were published as well, and it didn’t redirect.- This reply was modified 3 months, 3 weeks ago by Munford.
July 25, 2024 at 7:33 pm #1462993Hi,
Thank you for your patience, I changed it to this and it seems to work now, please check:function custom_redirect_after_login( $redirect, $user ) { // URL of your custom My Account page $custom_account_page_url = site_url( '/dashboard/' ); // Check if the user is logging in from the specific login page if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '/for-medlemmer/' ) !== false ) { return $custom_account_page_url; } return $redirect; } add_filter( 'woocommerce_login_redirect', 'custom_redirect_after_login', 10, 2 );
Best regards,
MikeJuly 25, 2024 at 8:55 pm #1463000yes that works thanks very much!
July 25, 2024 at 11:54 pm #1463006Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘woocommerce login redirect to another page’ is closed to new replies.