Website Building » WooCommerce » How Do I Turn Off Search in WooCommerce?

How Do I Turn Off Search in WooCommerce?

Last updated on January 23, 2023 @ 11:46 am

Are you using WooCommerce and want to know how to turn off the search function? By default, WooCommerce comes with a search bar that allows customers to search for products on your site. However, you may want to disable this feature for various reasons. For example, you may be selling products that are not meant to be found by customers searching for them on your site. Or, you may simply not want customers to be able to search your site at all.

Whatever your reason, disabling the WooCommerce search bar is easy to do.

To turn off search in WooCommerce, you need to edit your theme’s functions.php file. You can do this via FTP or by logging into your WordPress dashboard and going to Appearance > Editor. Once in the editor, select the functions.php file from the list of files on the right hand side. Then, add the following code to the bottom of the file and save your changes:

function wc_remove_all_filters( $tag ) {global $wp_filter;
if ( isset( $wp_filter[$tag] ) ) {unset( $wp_filter[$tag] );}}
add_action( 'init', 'wc_remove_all_filters', 10 );
 function wc_disable_search() {if ( function_exists( 'WC' ) && ! is_admin() && is_search() && isset( $_GET['post_type'] ) &&  $_GET['post_type'] == 'product' ) {wp_redirect( home_url() );exit;}}
add_action( 'template_redirect', 'wc_disable_search' );

The first line of code removes all filters from the "init" action. This action is used by WooCommerce to initialize its search functionality.

The second line of code redirects users away from the product search results page if they try to access it. This will prevent users from seeing any products that may be listed on that page.

PRO TIP: If you are using WooCommerce to sell products on your WordPress site, you may want to disable the search feature. This can be done in the WooCommerce settings. However, disabling search will also remove the search bar from your theme.

That's all you need to do to disable search in WooCommerce! Keep in mind that this will also disable product sorting and filtering options on your shop page.

If you want to keep those features enabled, but still want to disable product search, you can use a plugin like WooCommerce Shop Page Only. This plugin will allow you to keep sorting and filtering options enabled while still hiding the product search bar.

Conclusion:

Turning off search in WooCommerce is easy to do by editing your theme's functions.php file and adding a few lines of code. This will also disable product sorting and filtering options on your shop page. If you want to keep those features enabled, but still want to disable product search, you can use a plugin like WooCommerce Shop Page Only.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.