1) Only paste this code snippet in your child theme's function.php.

 

add_action('template_redirect','hide_course_from_visitor');
function hide_course_from_visitor(){
 if (!is_user_logged_in()){
 wp_redirect(home_url(),'302');
 }
}