我需要将产品标签移至 WooCommerce 产品描述的底部。
我在用"将自定义内容添加到 WooCommerce 产品描述中"答案代码确实有效,我在产品描述下方收到文本“这是描述中的最后一行”...
现在我想添加产品元信息(产品 SKU 和标签),但我不知道该怎么做。
任何帮助表示赞赏。
我正在使用 Storefront 子主题...
产品元数据与模板一起显示single-product/meta.php
,所以你只需要使用专用函数来调用它wc_get_template()
.
现在,由于这是在过滤器挂钩中使用的,其中使用变量返回显示,因此您需要启用 PHP 缓冲...
这是最终的代码:
// remove the product meta data
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_filter( 'the_content', 'woocommerce_product_description_and_meta' );
function woocommerce_product_description_and_meta( $content ) {
// Only for single product pages (woocommerce)
if ( is_product() ) {
global $post, $product;
ob_start(); // Start buffering
// The product meta information
wc_get_template( 'single-product/meta.php' );
// Inserting the product meta information display at the end
$content .= ob_get_clean(); // append the buffered display
}
return $content;
}
代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。
可以用不同的方式来完成:将产品元移至 WooCommerce 中的描述选项卡
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)