How to remove breadcrumbs, result count, etc from pages in WooCommerce

If you’ve worked with WooCommerce, then you know that it is PACKED with features. These are awesome! Sometimes, however, you need to get rid of some of the stuff that WooCommerce spits out by default. Luckily, we can do that relatively easily.

Setting Up

When I work with WooCommerce, one of the first things I do is create a WooCommerce specific functions.php file that I can store my WooCommerce related general functions in. Create a woocommerce subfolder in your main theme folder. In this new folder, create a new file (I usually call mine functions.php).

Now, go to your main theme’s functions.php and include or require the new file you created.

require 'woocommerce/functions.php';

Since we are working with WooCommerce, we want to make sure that our theme declares support for it. Add the following line to your newly created woocommerce/functions.php file.

add_theme_support( 'woocommerce' );

Now that we have our woocommerce specific functions file created, we have a place to add code that directly effects our WooCommerce installation/display that is separate from our theme’s normal functions.php file.

WooCommerce Conditional Tags

Probably the easiest part of this tutorial! WooCommerce has a nice page that documents all the different conditional tags that you would need. http://docs.woothemes.com/document/conditional-tags/ For the purposes of this tutorial, we will need the is_product_category() and is_shop() functions.

Remove breadcrumbs and result count from category page

If you look through the template files for WooCommerce, you’ll notice that pretty much everything is handled through actions. Basically, you use add_action() to add your functions to an action that is later called in the template through the do_action() function. Here is an example do_action() taken from a WooCommerce template.

/**
 * woocommerce_before_main_content hook
 *
 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
 * @hooked woocommerce_breadcrumb - 20
 */
do_action( 'woocommerce_before_main_content' );

WooCommerce gives us everything we need to add to this hook and to remove actions from it. In the comment for the above do_action(), you can see that it shows the different functions that are hooked in to this action and it tells you the priority of the action. To remove an action from a hook, we need both of those pieces of information. Adding the following bit of code to your newly created functions.php file, we will remove the breadcrumbs and the result count from the archive and main shop page.

/*
 * Remove actions from specific pages
 */
add_action( 'wp_head', 'theme_woo_remove_actions' );
function theme_woo_remove_actions() {
    // check if is product cat or main shop page
    if ( is_product_category() || is_shop() ) {
        // remove the breadcrumbs from archive page
        remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );

        // remove the result count
        remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
    }
}

Everything above should make sense. We create a new function that removes the actions we want to remove from the various registered actions. In the add_action() line, we add the new function to the wp_head() action. The wp_head() action gets called wherever the wp_head() function is (usually in header.php). The reason we hook into this is because when that function calls the page is loaded from the database and our conditional functions will actually work.

Summary

That should sum it up! WooCommerce is an awesome & powerful eCommerce solution for WordPress. I hope that this tutorial helps make your life developing with it a little easier.

Join the Conversation

No comments

  1. Thanks for this Zach. Curious though, no matter what I do or try, I can NOT remove the result count on my shop page. I’ve tried your code and others, but nothing takes it out.

    I’ve removed the sorting drop down no problem, but can’t remove the result_count section.

    Not only want it gone, but would be nice to use the space.

    Any thoughts?

      1. Thanks for the reply Zach.

        I tried placing it in my theme’s function file (well child theme), but it did not take the code out for me. I tried the code you posted above. I have been able to remove the “Sort by” section, but I did that with CSS. I’d rather remove that entire space, so I don’t end up with too much white space. If that is even possible.

        I sell digital products, so those two options don’t really apply anyway.

        I am going to try another theme, maybe I’ll have better luck. I’ll report back 🙂

    1. The only way I’ve been able to remove these areas without CSS is by calling the functions themselves and having them return nothing (I added this code to a plugin I wrote to alter other plugins, but it can be added to your functions.php file).

      If you want these to only alter the shop page, you’ll need to write an if statement because right now, these will affect all pages where those functions are used.

      //* Remove ‘Showing Results’
      function woocommerce_result_count() {
      return;
      }

      //* Remove ‘Product Sorting’ form
      function woocommerce_catalog_ordering() {
      return;
      }

  2. Thanks for the clear tutorial! But unfortunately it didn’t work for me either. But it worked when I placed the code in the functions.php of my theme (so not in the woocommerce folder).

    1. Hey Carsten!

      Once you create that file, you need to include it in your main `functions.php` file. If you don’t, than WordPress doesn’t know the file exists.

      1. Hi Zach, thanks for your reply. Aha, I see now that you explain this in the ‘Setting Up’ section. It would be a big help if you also have a specific code (in a SyntaxHighlighter) for this included in your tutorial. Then I would give it 5 stars! 🙂 After I added the ‘required’ line it all worked as expected. Thanks again!

        1. Great point- I went ahead and updated the post. Thanks for providing feedback!

          Glad you got it working 🙂

Leave a comment

Your email address will not be published. Required fields are marked *