Skip foreach loop

In line 195 you’re using get_categories, which can be filtered to exclude specific category numbers, either through an array of arguments, or a query string. Since $options is already set, you could add to it before you call get_categories:

if ($show_assigned_categories == 'true' && is_single()) {
        $categories = get_the_category();
} 
else {
    $options['exclude'] = '1,2,3'; // your comma-separated list goes here
    $categories = get_categories($options);
}