No Results in WooCommerce Product Search

I got this solution from https://stackoverflow.com/a/57218305/900557

Add this to your theme’s functions.php

The Answer from Chandrakant Devani helped, but broke other searches in the admin. Adding an if seems to avoid breakages

if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product')

full code:

add_action( 'pre_get_posts', 'products_pre_get_posts' );
function products_pre_get_posts( WP_Query $query ) {
    if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product' ) {
        $query->set( 'tax_query', array(
            array(
                'taxonomy' => 'product_cat',
                'field'    => 'term_id',
                'terms'    => get_terms( array( 'taxonomy' => 'product_cat', 'fields' => 'ids' ) )
            )
        ) );
    }
}

I don’t know enough about woocommerce to know why this is needed, but it fixed our problem