Hi,
How can we use the search bar for products from Woocommerce plugin and not for Post? as we are using the theme for ecommerce
Thank you
Hello,
Thank you for writing in!
Remember that you need to use the Child theme and add this code in your functions.php
add_filter( 'pre_get_posts', 'custom_search' );
function custom_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'product' ) );
}
return $query;
}
Hi,
This function does also affect all of my search on my site.
When searching for a customer etc, the result only show product.
How can I group this function only to the product search?
Hello There,
Thanks for updating in! Please remove the code as it applies to the whole site.
In your widgets area, please make sure that you added the “WooCommerce Product Search” widget and not the default “Search” widget. I would highly recommend that you create a sidebar and assign this sidebar to appear in all WooCommerce pages and product pages. In this same sidebar, you will need to insert the “WooCommerce Product Search”.
Hope this helps.