If the user is logged-in, the function returns before the redirect code lower in the function.
if( is_user_logged_in() ) {
return;
}
Since you want the redirect code to run only if the user is logged in, try this:
if( ! is_user_logged_in() ) {
return;
}