• Resolved mmtomm

    (@mmtomm)


    Hi,

    is it possible, to make the search box in the theme header (or at the bottom in mobile view) searching not only for products but also for content in pages and posts?

    Thank you
    Tom

Viewing 1 replies (of 1 total)
  • Hi there,

    In order to do that, you’ll need to change the product search widget from WooCommerce. Storefront uses that widget through the get_product_search_form() function. The HTML can be changed by using a filter. Like so:

    add_filter( 'get_product_search_form', 'get_custom_product_search_form', 10, 1 );
    
    /*
     * Overrides WooCommerce default product search form.
     *
     * @param string $form Form default HTML markup.
     * 
     * @return string
    */
    function get_custom_product_search_form( $form ) {
    	$form = str_replace( '<input type="hidden" name="post_type" value="product" />', '', $form );
    	return $form; 
    }

    Basically, this filter will remove the post_type input, resulting in a general search on the website.

    Note: Searching for other types of posts, not only products, will change the search results appearance in Storefront.

    I hope this helps.

    Best,
    Ricardo

Viewing 1 replies (of 1 total)
  • The topic ‘Search for products and pages in one search box’ is closed to new replies.