用于呈现“描述”选项卡的回调是woocommerce_product_description_tab()
, 只需加载模板文件single-product/tabs/description.php
. 对于“附加信息”选项卡,回调是woocommerce_product_additional_information_tab()
模板是single-product/tabs/additional-information.php
.
因此,如果要合并这两个选项卡,可以从模板文件中复制“相关”内容,如下所示:
add_filter( \'woocommerce_product_tabs\', \'exetera_custom_product_tabs\', 98 );
function exetera_custom_product_tabs( $tabs ) {
// Custom description callback.
$tabs[\'description\'][\'callback\'] = function() {
global $post, $product;
// Display the content of the Description tab.
the_content();
// Display the heading and content of the Additional Information tab.
echo \'<h2>Additional Information</h2>\';
do_action( \'woocommerce_product_additional_information\', $product );
};
// Remove the additional information tab.
unset( $tabs[\'additional_information\'] );
return $tabs;
}
在这里,我们只调用默认回调,对于“描述”选项卡,我们禁用默认标题文本。
add_filter( \'woocommerce_product_tabs\', \'exetera_custom_product_tabs\', 98 );
function exetera_custom_product_tabs( $tabs ) {
// Custom description callback.
$tabs[\'description\'][\'callback\'] = function() {
// Disable the "Description" heading.
add_filter( \'woocommerce_product_description_heading\', \'__return_empty_string\' );
// Display the content of the Description tab.
woocommerce_product_description_tab();
// Enable the "Description" heading.
remove_filter( \'woocommerce_product_description_heading\', \'__return_empty_string\' );
// Display the heading and content of the Additional Information tab.
woocommerce_product_additional_information_tab();
};
// Remove the additional information tab.
unset( $tabs[\'additional_information\'] );
return $tabs;
}