您可以保留第一行代码。然后在产品描述选项卡上插入单个产品元,在描述之前,您可以使用两种不同的方式:
1)。使用 Hooks 如下:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_filter( 'woocommerce_product_tabs', 'woocommerce_custom_product_tabs', 999 );
function woocommerce_custom_product_tabs( $tabs ) {
// We overwrite the callback function with a custom one
$tabs['description']['callback'] = 'woocommerce_product_meta_and_description_tab';
// (optional) We can also overwrite the title
$tabs['description']['title'] = __('Meta and description', 'woocommerce');
return $tabs;
}
function woocommerce_product_meta_and_description_tab() { // this is where you indicate what appears in the description tab
wc_get_template( 'single-product/meta.php' ); // The meta content first
wc_get_template( 'single-product/tabs/description.php' ); // The product description after
}
代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。
2)。或覆盖模板:
您可以按照this official documentation 中的说明通过您的主题覆盖single-product/tabs/description.php 模板文件。
将文件复制到活动主题内的woocommerce 文件夹后,打开编辑single-product/tabs/description.php 文件并在其中添加以下行:
wc_get_template( 'single-product/meta.php' );
它将在产品描述选项卡中显示产品元信息。
不要忘记保存在您的活动子主题的functions.php文件中:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
相关:WooCommerce action hooks and overriding templates