这篇文章是转载的国外的,我保留了英文原版,并附上了中文翻译。
The good news is that we do not have to deal with sorting arrays like we did with my account menu or admin columns for example.
好消息是,我们不必像处理我的帐户菜单或管理列那样处理排序数组。
Each of the tabs has its own priority value:
每个选项卡都有自己的优先级值:
- Description –
10
, 描述-10
, - Additional information –
20
,
附加信息-20
, - Reviews –
30
. 评论-30
。
We can easily display the “Reviews” tab first by changing this parameter with the hook:
我们可以很容易地显示“评论”标签,首先通过改变这个参数与挂钩:
add_filter( 'woocommerce_product_tabs', 'misha_change_tabs_order' ); function misha_change_tabs_order( $tabs ) { $tabs[ 'reviews' ][ 'priority' ] = 5; return $tabs; }
As you can see on the screenshot below, this code snippet didn’t only change the tab order but it also redefined which tab is opened by default.
正如你在下面的屏幕截图中看到的,这个代码片段不仅改变了标签顺序,而且还重新定义了默认打开的标签。
One more thing – that hook priority in this case must be 98
or below! It is because the array sorting function is also connected to this hook and has 99
priority, so if you set it to 99
or more than 99
, the code will have no effect at all.
还有一件事–在这种情况下,钩子的优先级必须是 98
或更低!这是因为数组排序函数也连接到这个钩子上,并且具有 99
优先级,所以如果你将它设置为 99
或超过 99
,代码将完全没有效果。
// it is OK add_filter( 'woocommerce_product_tabs', 'misha_change_tabs_order', 98 ); // NOT OK add_filter( 'woocommerce_product_tabs', 'misha_change_tabs_order', 99 );
You may be also interested in how to remove default tabs, rename them or even create your own custom tab.
您可能还对如何删除默认选项卡、重命名它们甚至创建自己的自定义选项卡感兴趣。