Skip to content

Snippet: Modify the WooCommerce Search Results Layout

The WooCommerce search results page uses the same search template as all the shop archives which you can alter at Appearance > Customize > WooCommerce (Total) > Shop & Archives > Layout.

Now, if you need to customize the layout of your WooCommerce search results but keep your main shop page and archives using the same layout as defined in the customizer you will need to use a little code to conditionally set the layout of the search results and you can do so using the following snippet.

/**
 * Modify the WooCommerce Search Results Layout.
 *
 * @link https://total.wpexplorer.com/docs/snippets/woo-search-layout/
 * @param string $layout full-width, left-sidebar, right-sidebar
 */
add_filter( 'wpex_post_layout_class', function( $layout ) {
	if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && is_search() ) {
		return 'right-sidebar';
	}
	return $layout;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top