How to remove search from the menu on specific pages?

Posted in: Newspaper
Post count: 200

Hi tagDiv team,

I recently installed Woocommerce and need the search function on all woocommerce pages to search only within woocommerce products. Currently the default search returns results that include all posts on the site including product pages and post pages.

I need to either change the function of the theme’s default search in the menu to search only within woocommerce products while the user is on a woocommerce page (this would be really the best scenario), or
to stop the function for the default search so that it is not loaded on woocommerce pages at all (and use woocommerce search). If the second scenario is used, I would like to use the best option for this from optimization point of view – not load the search function on woocommerce pages at all, or hide the search from the menu.

p.s. We have some standard pages like: Cart, Order, Order received – that are non-woocommerce pages, but should be included to the rule above.

Big Thanks in advance for your time!

Post count: 22421

Hello,

Sorry but our theme has no option for either scenarios so there is no convenient click of a button way to do it.
Our theme uses the default search of wordpress and adds a live search to it but the content grabbed is set by wordpress. You will have to search for a plugin or a method of changing the default search of wordpress.

The second option by removing the search from the menu on woocommerce pages is simpler as you can use this function:
https://docs.woocommerce.com/wc-apidocs/function-is_woocommerce.html
You can wrap the theme code in this function (the revers using an exclamation mark in front) so the theme search will show up only when the template is not a woocommerce code. The file you need to alter is here: https://www.screencast.com/t/m4IMj2SXC65i and https://www.screencast.com/t/DcTcRSoq

Thank you!

Post count: 200

Hi Bogdan,

Thank you for your reply. Unfortunately I don’t quite understand what to do to achieve the solution with removing the search from the menu on woocommerce pages.
Here are the 2 files you are describing, and I see that I already have the function is_woocommerce in the header-menu.php file.

I also would like to remove the search from the menu on specific pages that are non-woocommerce, like for example the Cart and Order pages.

Any further support is much appreciated!

Thank you!

Post count: 20688

Hi,

You could simply try a code like this to remove the header search in this situation

.woocommerce #td-top-search,
.woocommerce-page #td-top-search,
.woocommerce-cart #td-top-search {
display: none;
}

It should cover most of the Woocommerce pages, cart and order pages.

Thanks

Post count: 200

Thanks Simion! It works best when added to the style.css in the child theme.

Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newspaper’ is closed to new topics and replies.