Can't remove woocommerce sidebar

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

Topic woocommerce-offtopic sidebar Wordpress

Category Web


For me it works with the following code, but I'm not sure if this is really viable and future proof.

function woo_remove_sidebar() {              
    if( ! is_product() or
        ! is_cart() or
        ! is_checkout() or
        ! is_account_page() )
    {
        remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
    }
}
add_filter( 'is_active_sidebar', 'woo_remove_sidebar' );

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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.