6
votes

Like many people that start using woocommerce for the first time I need to know how to customise it. In my particular situation I want to remove the sidebar from the Cart, Checkout and single product pages. My sidebar is defined and called from sidebar.php using the code below:

<?php dynamic_sidebar('global-sidebar'); ?>

I have tried for a long time to find an answer that works but I can't seem to find the correct code or solution. Perhaps asking the question myself will work. By the way I really appreciate the answers in the other articles and how-to's but they don't work for me.

Before I go any further I am using Bootstrap (latest version as of 2014) to style my Wordpress website. Not sure if that matters but maybe it does somehow.

Can someone please tell me how I find and then tell Woocommerce not to display any kind of sidebar on the Cart, Checkout and Single Product pages?

p.s. The website can be found here > wp.wunderful.co.uk (staging site for a client website project)

6
Did you check the widgets menu on those pages?Siyah
I'm not familiar with how the widgets work on these pages. The woocommerce pages confuse me, hence the request for help. Thank you for your comment though.Oliver Martin
If it is alright with you, I can check it for you in the admin panel.Siyah
I am avoiding doing this so no sorry.Oliver Martin

6 Answers

6
votes

Go to "Cart" page from dashboard pages, from "Page Attribute Section" -> "Templates" choose "Full Width" this will give you a page without sidebar.

5
votes

In theory, something like the following ought to work, but I haven't tested it. (To be added to your theme's functions.php)

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

If you look at the Woo templates you will see

<?php
    /**
     * woocommerce_sidebar hook
     *
     * @hooked woocommerce_get_sidebar - 10
     */
    do_action( 'woocommerce_sidebar' );
?>

This is Woo saying: "Display the sidebar here". But it is adding the woocommerce_get_sidebar function to the woocommerce_sidebar hook... which is convenient because it allows you to unhook that function like I've shown above. Finally, I am using Woo's conditional logic to only unhook the function from its action on the pages you requested.

I'm running my function on the woocommerce_before_main_content hook, which I think should work assuming your theme hasn't removed that hook. If so, then you could probably use wp_head or something that is guaranteed to be there, though then you'd probably want to check that the is_checkout(), etc functions exist or risk breaking your theme should you ever deactivate WooCommerce. As I have it, i should only run on WooCommerce-specific pages and so checking if the WooCommerce functions are defined is probably overkill.

Important Note:

This assumes the default theme or a theme that isn't running its own custom sidebar functions. If your theme is doing something else you will need to investigates its particular functions and templates.

1
votes

What you should do is to create a files called woocomemrce.php in your theme if it doesn't already exists. Then you should look at your page template files for full width and for page with sidebar to see how they are structured and see where they differ. Then copy the contents of one the files into woocommerce.php and replace the loop with woocommerce_content(), see this page for details. Lastly see where the different page templates differ and then use if-statements in the places where they differ.

if( is_post_type_archive( 'product' ) ) :
    //Content to display in the list view (i.e. with sidebar)
else :
    //Content to display all other views (i.e. without sidebar)
endif;
1
votes
.woocommerce-cart .sidebar {
    display: none;
}

.woocommerce-cart .content-area {
    width: 100%;
}

add this in custom/style.css.

1
votes

From

https://wordpress.org/support/topic/remove-sidebar-for-woocommerce-cart-and-checkout-pages/

On your theme, likely subtheme, function.php

add_action('wp_head', 'hide_sidebar' ); function hide_sidebar(){ if(is_cart() || is_checkout()){ ?>
<style type="text/css">
    #secondary {
        display: none;
    }
</style>
<?php
}
0
votes

To remove sidebar from the Cart, Checkout and single product pages you want to use action hook in function.php file -

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

Here you can get WooCommerce Action and Filter Hook -https://docs.woothemes.com/wc-apidocs/hook-docs.html