How to redirect a user to my-account/orders correctly
Try this:
add_action( 'parse_request', 'redirect_to_my_account_orders' );
function redirect_to_my_account_orders( $wp ) {
// All other endpoints such as change-password will redirect to
// my-account/orders
$allowed_endpoints = [ 'orders', 'edit-account', 'customer-logout' ];
if (
is_user_logged_in() &&
preg_match( '%^my\-account(?:/([^/]+)|)/?$%', $wp->request, $m ) &&
( empty( $m[1] ) || ! in_array( $m[1], $allowed_endpoints ) )
) {
wp_redirect( '/my-account/orders/' );
exit;
}
}