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.


Discover more from zach wills

Subscribe to get the latest posts sent to your email.