1

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.

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?

2
  • i think u need to add this line also on the single-product template file - remove_action( 'woo_main_after', 'woocommerce_get_sidebar', 10)
    – Shazzad
    Jan 4, 2014 at 3:24
  • Tried but not worked. Jan 4, 2014 at 3:55

3 Answers 3

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/

4
  • is_product() is just a wrapper for is_singular('product'). So, both works exactly the same.
    – Abhik
    Jan 4, 2014 at 12:31
  • You would need to add the single product page slug if ( is_product('t-shirt') ) { Jan 4, 2014 at 12:36
  • And how if I want to remove it for all products? I mean, no specific ID Jan 5, 2014 at 22:15
  • if ( is_product() ) { Jan 5, 2014 at 22:28
0

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');
2
  • Abhik, the code looked promissing but not worked too. Wonder if "product" is the real ID of single-product page. Thank you anyway. Jan 4, 2014 at 3:58
  • @serranegra my bad. init is too late to remove the action. Code corrected and should work fine now.
    – Abhik
    Jan 4, 2014 at 6:34
0
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%;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.