How to change the WooCommerce login redirect from my account page, and send your users to your homepage
add_filter('woocommerce_login_redirect', 'wc_login_redirect', 10, 2 ); function wc_login_redirect( $redirect_to, $user ) { $role = $user->roles[0]; $myaccount = get_permalink( wc_get_page_id( 'myaccount' ) ); if( $role == 'customer' ) { $redirect_to = home_url(); } return $redirect_to; } // If you'd like to redirect the customer back to the previous page he/she visited, then replace // $redirect_to = home_url(); with $redirect_to = wp_get_referer() ? wp_get_referer() : home_url();
Was this helpful? Please buy me a coffee
This code should be added to your child theme’s
functions.php
file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php
file as this will be wiped entirely when you update.