• Skip to main content
  • Skip to primary sidebar

Mintstone

Custom Website Development

  • Home
  • Capabilities
    • Website Design
    • Custom Solutions
    • Technical Support
  • Portfolio
  • About
  • Contact Us

August 30, 2018

Implementing WooCommerce Product Search for all products in a multisite

This is pretty straightforward to achieve using a few lines of code within the archive-product.php page template.

Remember to override this correctly you’ll need to copy the file from it’s default location /wp-content/plugins/woocommerce/templates/archive-product.php into /wp-content/themes/your_theme/woocommerce/archive-product.php, then open this version of the file & edit it as follows:

Scroll down to line 47 (at the time of blogging!!)

//insert network search code here...

if ( is_search() ) {
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();

$searchfor = get_search_query();
$query_string=esc_attr($query_string);
$blogs = get_sites();
foreach ( $blogs as $blog ):
switch_to_blog($blog->blog_id);
$search_query = new WP_Query($query_string);
while ( $search_query->have_posts() ) {
$search_query->the_post();
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
restore_current_blog();
endforeach;

woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
}
else{
//end of network search code =)
if ( woocommerce_product_loop() ) {

Finally you’ll need to add a closing curly bracket (brace) to line 92, right before this line of code
/**
* Hook: woocommerce_after_main_content.

Filed Under: PHP/MySQl, WordPress

Primary Sidebar

Categories

  • Genesis
  • Gravity Forms
  • PHP/MySQl
  • Popups
  • Search
  • WordPress
Copyright © 2023 - Mintstone Software Solutions | All Rights Reserved | Privacy Policy | Sitemap