[Support request] All or specific search forms to return WooCommerce products only results

Home Forums Support All or specific search forms to return WooCommerce products only results

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #367838
    onlyonemj

    Hello one and all!

    Is there a way to make all or specific search forms/fields (in navigation menu and elsewhere) to return the search results in the same way you’d get when using the WooCommerce product search widget?

    When you use the WooCommerce product search widget it returns search results from within the shop page using the following ?s=&post_type=product parameter. That’s how I’d like all or specifically targeted search boxes to show results. Not as default where it lists all blogs and products on one page outside of the shop environment.

    Thanks for any pointers on this!

    #367971
    Leo
    Staff
    Customer Support
    #380958
    onlyonemj

    Thanks Lee,

    That helped hugely. Sorry for the delayed reply – other priorities took over until I’ve rounded back to this.

    The code you gave in the link needs updating as there’s a typo where value=”products” should be value=”product”.

    Here’s the working code for anybody who needs it:

    add_filter( 'generate_navigation_search_output', 'tu_wc_navigation_search' );
    function tu_wc_navigation_search() {
    	printf(
    		'<form method="get" class="search-form navigation-search" action="%1$s">
    			<input type="search" class="search-field" value="%2$s" name="s" title="%2$s">
    			<input type="hidden" name="post_type" value="product">
    		</form>',
    		esc_url( home_url( '/' ) ),
    		esc_attr( get_search_query() ),
    		esc_attr_x( 'Search', 'label', 'generatepress' )
    	);
    }

    Thanks for the support!

    Mike

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.