WooCommerce Product Search Error

" Invalid argument supplied for foreach()" . means that the $parents variable is not an array so you can’t loop through it. You should wrap the foreach loop in an if check that verifies that $parents is something valid.

<?php
   $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
   $parents = get_the_terms($term->parent, get_query_var('taxonomy') );

   if( $parents && ! is_wp_error($parents) ) :

     echo "<div class="product-cat">";
     echo "In"." "." ";
     foreach( $parents as $parent ) {
      echo '<a href="'.get_term_link($parent).'">'.$parent->name.'</a>';
     }
     echo "</div>";

   endif;

?>

Though secondarily…. get_query_var('term') and get_query_var('taxonomy') are not returning anything on the search page because those query vars don’t pertain to the search query.