将产品元数据移动到WooCommerce中的“描述"选项卡 [英] Move product meta to the description tab in WooCommerce
问题描述
如何将产品meta移至产品描述"标签的开头? 我尝试:
How to move the product meta to the beginning of the product description tab? I try:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_product_tabs_description', 'woocommerce_template_single_meta', 10 );
删除有效,但add_action()
无效.
推荐答案
您可以保留第一行代码.然后,在产品说明标签上插入单个产品元数据之前,可以使用2种不同的方式:
You can keep the first code line. Then to insert single product meta on product description tab, before description, you can use 2 different ways:
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文件中.经过测试,可以正常工作.
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
2).或覆盖模板:
您可以通过主题覆盖single-product/tabs/description.php
模板文件,如此官方文档中所述.
You can override single-product/tabs/description.php
template file via your theme as explained in this official documentation.
将文件复制到活动主题内的woocommerce
文件夹后,打开编辑single-product/tabs/description.php
文件并在其中添加以下行:
Once you have copied the file to the woocommerce
folder inside your active theme, open edit single-product/tabs/description.php
file and add the following line inside it:
wc_get_template( 'single-product/meta.php' );
它将在产品描述"标签中显示产品元信息.
It will displays the product meta information inside the product description tab.
别忘了保留活动子主题的functions.php文件:
Don't forget to keep in your active child theme's functions.php file:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
这篇关于将产品元数据移动到WooCommerce中的“描述"选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!