3
votes

I need to remove sidebar into my woocommerce store. I have tried with backend in option theme and in each category but resultless.

I tried also:

1.file wp-template-hooks.php removed--> do_action(..

2.file archive-product.php removed--> do_action(..

  1. insert in file function.php in theme dir and function.php in woocommerce dir remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );

  2. into database there is 2 tables with 2 fields serialised but is a risk change this.

resulless.

I finished the ideas. Where is saved into db the visibility of sidebar? or the variable?

Can you help me?

Thanks Ale

8

8 Answers

6
votes

I just wanted to update this post for WooCommerce version 3.2.3 - 2017

OK the WooCommerce Plugin includes a folder with all the template files if you want to make changes to the template on a custom theme or child theme you need to copy all of the desired template into a folder called woocommerce in your root theme folder. This will overwrite the plugin templates and will allow for WooCommerce updates with overwriting your custom changes. These templates have all of the do_actions and hooks in the comments so it makes it easy to understand how it's working.

That said WooCommerce has hooks that allow for you to add or remove blocks of code you can check out the API Docs here.

To remove the side bar you need to add this into your functions.php file in your theme setup function

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

Please, add this code to your functions.php

function mb_remove_sidebar() {
    return false;
}

add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );
1
votes

You have already integrated WooCommerce in your theme?

If not, try to do this three steps for integration WooCommerce in your theme.

After that, remove get_sidebar(); from your_theme/woocommerce.php

It works fine for me. Screenshot here.

Hope it helps.

1
votes

Further to @maksim-borodov's answer, I wanted to hide the sidebar conditionally, i.e. only on Product pages. Here's how:

function remove_wc_sidebar_conditional( $array ) {

  // Hide sidebar on product pages by returning false
  if ( is_product() )
    return false;

  // Otherwise, return the original array parameter to keep the sidebar
  return $array;
}

add_filter( 'is_active_sidebar', 'remove_wc_sidebar_conditional', 10, 2 );
0
votes

Add to functions.php the following line:

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

0
votes

I am using GeneratePress (free version), so the other solutions didn't work for me.

This page gave me the answer: https://docs.generatepress.com/article/sidebar-layout/#sidebar-filter

add_filter( 'generate_sidebar_layout', function( $layout ) {
    // If we are on a woocommerce page, set the sidebar
    if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
        return 'no-sidebar';
    }
    // Or else, set the regular layout
    return $layout;
 } );
-2
votes

This can be done by woocommerce sidebar plugin. If you want to remove by code add this code to functions.php,

  if (!class_exists( 'WooCommerce' ) ) {return;}

  if(is_cart() || is_checkout() || is_product() || is_shop() || is_account_page()){ 
  ?>
  <style type="text/css">
    #secondary {
        display: none;
    }
    #primary {
       width:100%;
    }
   </style>
  <?php
 }
}
-4
votes

Here is how to remove the sidebar :-

go to wp-content/plugins/woocommerce

in file single-product.php remove the following code -

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

next edit the file archive-product.php and remove the following code -

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

(tip* before deleting this, copy and paste the entire code from this page into a seperate text file on your HD...that way you can always paste the original code back into this folder if anything goes wrong)