How to Update my theme search template if products link are incorrect
When doing a WooCommerce MultiSite Search, the results are returned often within WooCommerce template called archive-product.php This is managed automatically through the internal code to return appropriate product link, depending on the shop in the network where is being located.
Some of WordPress Themes use their own search template. A commonplace for such code is the search.php file, within the theme directory. Using the default WordPress editor or a specialized tool, edit that file as follow:
Locate the following code in the template file:
while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content/content', 'excerpt' ); endwhile;
This need a bit of update to include the switch_to_blog() and restore_current_blog() so add the 2 new lines:
while ( have_posts() ) : the_post(); if ( isset($post->blog_id) ) { switch_to_blog ($post->blog_id); } get_template_part( 'template-parts/content/content', 'excerpt' ); if ( isset($post->blog_id) ) { restore_current_blog(); } endwhile;
At this point the products within the search interface include the correct links.