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

  • WooCommerce Cookbook
  • Patrick Rauland
  • 280字
  • 2021-07-23 19:35:09

Reordering product tabs

You may not want to remove product tabs entirely. You may only want to rearrange them. That can also be done with a bit of code.

Getting ready

You should know how to find the product tab ID. This is discussed in the first part of the preceding recipe, Removing product tabs.

How to do it…

To reorder product tabs, take a look at the following steps:

  1. Open up your theme's functions.php file, or a custom WooCommerce plugin that you have created, and paste in the following:
    add_filter( 'woocommerce_product_tabs', 'woocommerce_cookbook_reorder_tabs', 98 );
    function woocommerce_cookbook_reorder_tabs( $tabs )
    { 
        return $tabs;
    }
  2. In the woocommerce_cookbook_reorder_tabs function, you'll want to paste in the new order. Add the following code before the return $tabs; statement:
    if( isset( $tabs['reviews']['priority'] ) ){
        $tabs['reviews']['priority'] = 10;
    }
    if( isset( $tabs['description']['priority'] ) ){
        $tabs['description']['priority'] = 20;
    }
    if( isset( $tabs['additional_information']['priority'] ) ){
        $tabs['additional_information']['priority'] = 30;
    }

    Tip

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

  3. To make one tab appear before another, make sure it has a lower priority. In this case, we're making the reviews tab show up first, then the description, and finally the additional information tab.
  4. Save your file(s) and upload them. The product tabs should be rearranged.

How it works...

Just as in the preceding recipe, the woocommerce_product_tabs filter allows us to remove or alter the product tabs. In this case, we're only setting the priority of each tab. We aren't altering any other data.

主站蜘蛛池模板: 彭州市| 郑州市| 内黄县| 长乐市| 阳新县| 额尔古纳市| 宜黄县| 康平县| 江达县| 诏安县| 鄂伦春自治旗| 永登县| 社旗县| 汤原县| 若羌县| 龙门县| 镇雄县| 牡丹江市| 镇原县| 安化县| 大港区| 苍山县| 东源县| 观塘区| 通榆县| 监利县| 招远市| 嘉禾县| 怀集县| 丁青县| 昆明市| 普陀区| 禹城市| 景德镇市| 鄂伦春自治旗| 和平县| 聂拉木县| 修文县| 博罗县| 安庆市| 孝义市|