
上QQ阅读APP看书,第一时间看更新
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:
- 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.
- 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.
- You should be able to find
tabs
in the source code. - 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. - 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; }
- Now, in the
woocommerce_cookbook_remove_product_tabs
function, we have to specify exactly which tabs we want to remove. Just before thereturn $tabs;
line, add the following code:unset( $tabs['description'] );
- Replace
description
with the class of the tab you want to remove. For example, it could readunset( $tabs['description'] );
orunset( $tabs[additional_information] );
or something else based on extra plugins adding more tabs. - 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.