Hide products in uncategorized category from search results

Try to add the following lines of code at the end of your theme’s functions.php file:

function custom_pre_get_posts_query( $q ) {

$tax_query = (array) $q->get( 'tax_query' );

$tax_query[] = array(
    'taxonomy' => 'product_cat',
    'field' => 'slug',
    'terms' => array( 'uncategorized' ),
    'operator' => 'NOT IN'
);


$q->set( 'tax_query', $tax_query );

}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

Reference Site

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)