Removing product tabs

WooCommerce prints out all of the information about your products, which is generally pretty useful information for your customers. Sometimes, however, you may want to hide some of that information. With a bit of code, it's pretty easy to hide the product tabs.

Getting ready

You should have a simple product in your store.

How to do it…

To remove product tabs, we perform the following steps:

  1. Go to one of your products and find the tabs near the bottom of the product page, underneath the products' short description and the buy button.
    How to do it…
  2. Use a tool that allows you to browse the source of an HTML page. I'm using Google Chrome's Inspect Element; you could also use Firebug from FireFox.
  3. You should be able to find tabs in the source code.
    How to do it…
  4. Write down any of the classes of the tabs you want to hide. Omit the _tab syntax at the end of the class. You just need the first part.
  5. Now that we have the classes, we can write some code to hide those tabs. In your theme's functions.php file, add the following code:
    add_filter( 'woocommerce_product_tabs', 'woocommerce_cookbook_remove_product_tabs', 10 );
    function woocommerce_cookbook_remove_product_tabs( $tabs )
    { 
        return $tabs; 
    }
  6. Now, in the woocommerce_cookbook_remove_product_tabs function, we have to specify exactly which tabs we want to remove. Just before the return $tabs; line, add the following code:
    unset( $tabs['description'] );
  7. Replace description with the class of the tab you want to remove. For example, it could read unset( $tabs['description'] ); or unset( $tabs[additional_information] ); or something else based on extra plugins adding more tabs.
  8. Save the file and upload it to your site.

How it works...

The woocommerce_product_tabs filter allows you to add, rearrange, or remove tabs to suit your liking.

There's more…

It's actually a best practice to put this code in its own plugin rather than in your theme's functions.php file. For more details, refer to the Creating a WooCommerce plugin recipe in Chapter 1, WooCommerce Basics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset