将产品标签移至 WooCommerce 产品描述 [英] Move product tags to WooCommerce product description
问题描述
我需要将产品标签移到 WooCommerce 产品描述的底部.
I need to move product tags to bottom of WooCommerce product description.
我正在使用 "将自定义内容添加到WooCommerce 产品说明" 真正有效的答案代码,我在产品说明下方收到文本这是说明中的最后一行"...
I am using "Add custom content to WooCommerce product description" answer code that really works and I get text "This is the last line in the description" below product description...
现在我想添加产品元信息(产品 SKU 和标签),但我不知道该怎么做.
Now I would like to add the product meta information (the product SKU and the tags), but I don't catch how to do it.
感谢任何帮助.
我正在使用 Storefront 子主题...
I am using a Storefront child theme…
推荐答案
产品元数据与模板single-product/meta.php
一起显示,所以你只需要使用专用函数 wc_get_template()
.
The product meta data is displayed with the template single-product/meta.php
, So you just need to call it using the dedicated function wc_get_template()
.
现在因为它用于过滤器钩子,其中使用变量返回显示,您需要启用 PHP 缓冲...
Now as this is used in a filter hook where the display is returned using a variable, you need to enable PHP buffering…
这是最终的代码:
// 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 文件中.经测试有效.
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
以不同的方式完成:将产品元移动到 WooCommerce 中的描述选项卡
这篇关于将产品标签移至 WooCommerce 产品描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!