How To: Remove WooCommerce Sidebar

Advertisement

Here’s another snippet to remove WooCommerce sidebar in all single product pages, category or in specific product page only, sure you can remove the sidebar using CSS code but it’s not the good solution and for me it is ugliest solution out there, so in here we’re using hook, Woo recommended using hook for developer instead of touching or overwriting template file.

Without further ado lets get started.

Single Product Page

Remove sidebar in all single product pages


/* remove single product sidebar */
function woocommerce_remove_sidebar_shop() {
    if( is_product() )
       remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
}
add_action( 'template_redirect', 'woocommerce_remove_sidebar_shop' );

Specific Product Page

To remove sidebar on specific product page only, just add product ID in IF statement


// this remove sidebar in product page that has an ID of 4
if( is_product( 4 ) )
// code goes here!

All Pages

To remove sidebar in all pages including category then use this code instead


// add this code directly, no action needed
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );

Customising the full-width display is not covered in this tutorial.

Happy Coding ^_^

Advertisement