0

I am using this below code to remove woocommerce sidebar, from cart and single-product page.

function urun_sidebar_kaldir() {
    if ( is_product() || is_cart() ) {
        remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
    }
}
add_action( 'woocommerce_before_main_content', 'urun_sidebar_kaldir' );

It works in single-product page, but it doesn't work cart page.

I can't remove sidebar in cart page.

//Update

I am not using woocommerce.php in theme main folder.

And i have this templates in my theme.

wp-content/themes/{current-theme}/woocommerce/cart/cart.php

I created custom teplate for cart. And i removed get_sidebar(); but sidebar is still displaying in cart page.

wp-content/themes/{current-theme}/page-cart.php
wp-content/themes/{current-theme}/page-checkout.php
2

First, most themes have multiple page templates you can choose from.

Please check:

  1. go to cart page (in wp-admin).
  2. See side metabox 'Page Attributes'.
  3. There you can set the page template, does it have something like 'full_width'?

You can also try a different hook, like wp_head.

Example:

add_action( 'wp_head', 'urun_sidebar_kaldir' );

Let me know.


After checking the WOO cart template, i can't find a do_action( 'woocommerce_sidebar' ). It does exist in the singe-product.php template.

Are you certain the cart sidebar is generated by WooCommerce?


Add a full-width template to your theme:

Read this.

Then follow the steps i mentiod at the beginning of my answer.

  • I am developing a new theme. And i tried 'wp_head' and 'init' – bilimokur Jun 9 '18 at 8:09
  • See my updated answer – Bjorn Jun 9 '18 at 8:37
  • It not generated by Woocommerce. I tried remove get_sidebar() from page.php it removed from cart page too. But i wonder, why 'remove_action' working for single-product and not working for cart page. – bilimokur Jun 9 '18 at 8:45
  • Like i said: do_action( 'woocommerce_sidebar' ) does exist in the singe-product.php template. that's why your remove_action() is working for single products. If the cart sidebar is not generated by WOO, you'll have to find who/what is creating it. – Bjorn Jun 9 '18 at 9:30
  • Well that's kinda hard without knowing how you setup everything. Do you override the Woo cart template inside your theme? Does your theme default has a sidebar? Can't you create a no-sidebar template inside your theme? – Bjorn Jun 9 '18 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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