(WooCommerce) Remove Sidebar only on Single-Product page

I’m creating a theme and don’t want to display the sidebar on single-product’s page.

Following the recommendations of WooCommerce, I made a copy of “templates” folder (under woocommerce plugin) and installed on mytheme/templates, changing the folder’s name to “woocommerce“. On my theme’s root, I created a file called sidebar-shop.php.

Read More

By now I have the sidebar displayed on the shop page and on the single-product page. I tried to remove do_action('woocommerce_sidebar'); from woocommerce/single-product.php and also tried to create a conditional on woocomerce/shop/sidebar.php, something like:

if (!is_page('single-product') { 
    get_sidebar('shop'); 
}

but the sidebar remains.

Is there a working option to remove only the single product sidebar?

Related posts

3 comments

  1. The conditional tag for single products is is_product()

    add_action('template_redirect', 'remove_sidebar_shop');
    function remove_sidebar_shop() {
    if ( is_product('add-page-i.d-here') ) {
        remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar');
        }
    }
    

    You may also want to change the layout on that product page to full width to remove the gap and reduce the width of the content area using a custom body class which you can also generate conditionally.

    Woo Commerce conditional tags http://docs.woothemes.com/document/conditional-tags/

  2. Here it goes..

    function remove_sidebar_shop() {
        if ( is_singular('product') ) {
            remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar');
        }
    }
    add_action('template_redirect', 'remove_sidebar_shop');
    
  3. function remove_storefront_sidebar() {
        if ( is_product() ) {
        remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
        }
    }
    add_action( 'get_header', 'remove_storefront_sidebar' );
    

    It works with latest woocommerce 2.5.2
    Also CSS needed:

    .single-product.right-sidebar .content-area {
      float: none;
      margin-right: 0;
      width: 100%;
    }
    

Comments are closed.