I've been desperately searching for help with this. I would really love to remove the sidebar only from my woocommerce shop base page. In the admin options for my theme there's a place to enable the sidebar on the product page but what you select there impacts not just the shop base page but all of the archive pages.
Within the archive-product.php file there's code that controls the layout based on if that button is enabled so I thought my best bet would be to use an if else statement to say if its the shop page, use the 'no-sidebar' class. This is what I came up with but it's not working. Any thoughts would be fantastic.
<?php if ( is_object( $shop_page) ) : ?>
<div id="default_products_page_container" class="no-sidebar">
<?php elseif (have_posts() ) : ?>
<div id"default_products_page_container" class="with-sidebar">
Maybe check out the theme you are using and remove the code for the sidebar from the template.
In functions.php of your child theme:
// remove sidebar for woocommerce pages
add_action( 'get_header', 'remove_storefront_sidebar' );
function remove_storefront_sidebar() {
if ( is_shop() ) {
remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
}
}
and in css you'll have to change content class to be 100% width, for my theme:
.post-type-archive-product .content-area {
float: left;
margin-left: 0;
margin-right: 0;
width: 100%;
}
To remove sidebar from the shop page you want to use action hook in function.php file -
add_action('woocommerce_before_main_content', 'remove_sidebar' );
function remove_sidebar()
{
if ( is_shop() ) {
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
Remove the sidebar and make the page full width. This working example is the correct way to do it.
1 - The ID #secondary
is the sidebar ID. Make the page full with we apply style to #primary width:100%;
2 - The line if(is_cart() || is_checkout() || is_product())
removes the sidebar from cart, checkout, and product pages respectively.
add_action('wp_head', 'hide_sidebar' );
function hide_sidebar(){
if(is_cart() || is_checkout() || is_product()){
?>
<style type="text/css">
#secondary {
display: none;
}
#primary {
width:100%;
}
</style>
<?php
}
}