As already hinted by @Milo, check if you have terms before appending your tax_query
You can try the following: (Requires PHP 5.4+ due to short array syntax, revert to old syntax if necessary)
$args = [
'post_type' => 'product',
'posts_per_page' => 15,
'paged' => $paged,
'post__not_in' => $exclude,
's' => $filter,
];
// Append our tax-query if we have terms. Make sure it is a valid string or array
$term = 'DEFINE YOUR TERM HERE';
if ( $terms ) {
$args['tax_query'] = [
[
'taxonomy' => 'product_cat'
'terms' => $terms,
]
];
}
$q = new WP_Query( $args );