There are /login /register /lost-password /reset-password pages with content: [woocommerce_my_account].
After successful registration or login, the user is redirected thanks to:
function redirect_to_orders_after_login( $redirect, $user ) {
$redirect=site_url('/my-account/orders/'));
return $redirect ;
}
add_filter( 'woocommerce_login_redirect', 'redirect_to_orders_after_login', 10, 2 );
Dashboard menu item is hidden thanks to the below code:
function custom_my_account_menu_items( $items ) {
$items = array(
'orders' => __( 'Orders', 'woocommerce' ),
'edit-account' => __( 'Edit account details', 'woocommerce' )
);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
But if site_url/login and other above urls are accessed by a logged in users, my account dashboard is still displayed.
I tried to use the following code, but don't believe it covers all the cases, because accessing site_url/my-account/lost-password still redirects to the dashboard:
add_action('init', function() {
$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');
if ( is_user_logged_in() && ($url_path == 'login' | $url_path == 'register' | $url_path == 'lost-password' | $url_path == 'reset-password') ) {
wp_redirect( site_url('/my-account/orders/') );
exit();
}
});
Maybe, overriding dashboard.php with the code in orders.php in the child theme is the solution?
How to redirect a user to my-account/orders correctly and hide the dashboard so it won't be accessible and viewable at all?