Redirect Non-logged in users from viewing Free units

Add this code in your child theme functions.php :

add_action('template_redirect','wplms_Restrict_non_logged_user_free_unit');
 
    function wplms_Restrict_non_logged_user_free_unit(){
        if(!is_singular('unit'))
        return;
 
        $free = get_post_meta(get_the_ID(),'vibe_free',true);
        if(vibe_validate($free) && !is_user_logged_in()){
          wp_die('Access not allowed');
        }
    }