官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 安西县| 永州市| 莱州市| 信丰县| 陵川县| 丰顺县| 文山县| 莫力| 三门县| 石家庄市| 江津市| 浦北县| 裕民县| 八宿县| 通道| 剑河县| 重庆市| 宜城市| 如东县| 昆山市| 太谷县| 达日县| 墨竹工卡县| 肃宁县| 松江区| 德阳市| 定结县| 惠安县| 行唐县| 临邑县| 昌乐县| 宾川县| 阿克苏市| 承德市| 科技| 南平市| 五大连池市| 宝应县| 永胜县| 久治县| 西宁市|