skip to Main Content

I’m working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn’t have a sidebar, WooCommerce seems to have it.

For example, the shop page has it – I have tried a few things already and none work without caveats or didn’t work at all:

I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:

do_action( 'woocommerce_after_main_content' );

This didn’t work.

I then tried doing:

remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);

…this didn’t work either.

I found this answer and it worked, but didn’t make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn’t a great idea.

I also found this answer but it involves adding CSS, something I’d like to avoid as it isn’t the most robust method in-case class names change in the future etc…

Isn’t there a proper way of doing this without potential side affects?

2

Answers


  1. Chosen as BEST ANSWER

    With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:

    // Remove the sidebar
    add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
    
    // Removes the sidebar
    
    function blm_wc_remove_sidebar($index) {
        return false;
    }
    
    // Check to see if we're on a WooCommerce page and if so, remove the sidebar
    
    function blm_wc_remove_sidebar_check() {
        if ( is_woocommerce() ) {
            add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
        }
    }
    

    This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.

    Maybe there is a cleaner way to do this, but this worked for me.


  2. Please, add this code to your functions.php

    For remove only woocommerce side bar

     function disable_woo_commerce_sidebar_mms() {
            remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10); 
        }
        add_action('init', 'disable_woo_commerce_sidebar_mms')
    

    for remove all side bars

    function remove_sidebar_mms() {
            return false;
        }
    
        add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
    

    OR

    You can try this with to increase the priority hope fully its work

    remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search