如何修改Woocommerce产品选项卡顺序
Woocommerce产品选项卡默认排序是Description (描述),Additional information (额外信息),Reviews(评论 ),当我们添加更多的选项卡后,可能排序就不是我们所需要的了。
如果我们想自定义这个顺序,或者添加和删除某些选项卡。

修改选项卡顺序
只需在主题/子主题functions.php文件中添加一些代码。首先,我们需要定义一个数组来设置我们想要的选项卡顺序和标题:
每个选项卡都有自己的优先级值:
Description (描述) – 10,
Additional information (额外信息) – 20,
Reviews(评论) – 30.
值越大,排序越靠后。
例如:
我们可以通过使用钩子更改此参数来调整“评论”选项卡:
add_filter( 'woocommerce_product_tabs', 'mloun_change_tabs_order' );
function mloun_change_tabs_order( $tabs ) {
$tabs[ 'reviews' ][ 'priority' ] = 98;
return $tabs;
}
修改选项卡标题Description
使用woocommerce_product_tabs或woocommerce_product_description_tab_title 钩子
例如:Description 改成Overview
add_filter( 'woocommerce_product_tabs', 'mloun_rename_description_tab' );
function mloun_rename_description_tab( $tabs ) {
$tabs[ 'description' ][ 'title' ] = 'Overview';
return $tabs;
}
或者
add_filter( 'woocommerce_product_description_tab_title', 'mloun_rename_description_tab' );
function mloun_rename_description_tab( $title ) {
$title = 'Overview';
return $title;
}
如需要支持翻译,修改
$title = esc_html__( 'Overview' );
修改选项卡标题Additional information
例如:Additional information 改成Product size
add_filter( 'woocommerce_product_tabs', 'mloun_rename_additional_info_tab' );
function mloun_rename_additional_info_tab( $tabs ) {
$tabs[ 'additional_information' ][ 'title' ] = 'Product size';
return $tabs;
}
或者
add_filter( 'woocommerce_product_additional_information_tab_title', 'mloun_rename_additional_info_tab' );
function mloun_rename_additional_info_tab( $title ) {
$title = 'Product size';
return $title;
}
如需要支持翻译,修改
$title = esc_html__( 'Product size' );
修改选项卡标题Reviews
例如:Reviews改成What customers are saying
add_filter( 'woocommerce_product_tabs', 'mloun_rename_reviews_tab' );
function mloun_rename_reviews_tab( $tabs ) {
$tabs[ 'reviews' ][ 'title' ] = str_replace( 'Reviews', 'What customers are saying', $tabs[ 'reviews' ][ 'title' ] );
return $tabs;
}
或者
add_filter( 'woocommerce_product_tabs', 'mloun_rename_reviews_tab' );
function mloun_rename_reviews_tab( $tabs ) {
global $product;
$tabs[ 'reviews' ][ 'title' ] = 'What customers are saying (' . $product->get_review_count() . ') ';
return $tabs;
}
如需要支持翻译,修改
$tabs[ 'reviews' ][ 'title' ] = sprintf( esc_html__( 'What customers are saying (%d)' ), $product->get_review_count() );