[英]Display a custom field after product description in Woocommerce
add_action( 'woocommerce_product_description_tab', 'aq_display_disclaimer', 40, 9);
function aq_display_disclaimer() {
echo '<b>Disclaimer:</b> ' . get_field('product_disclaimer');
}
I am trying to display a WYSIWYG field on frontend but it is not displaying for some reason. 我试图在前端显示“所见即所得”字段,但由于某些原因未显示。 I also tried to use other functions like product_summary and before and after the_content and it works great.
我还尝试过使用诸如product_summary以及the_content之前和之后的其他功能,并且效果很好。
Any help would be highly appreciated. 任何帮助将不胜感激。 Ahmed Q.
艾哈迈德Q.
The
woocommerce_product_description_tab
it's not a hook but a function that is triggered as a callback for Product description tab.woocommerce_product_description_tab
不是钩子,而是作为产品描述标签的回调触发的函数。
It loads the templatesingle-product/tabs/description.php
, and you can't use it to add your product disclaimer.它会加载模板
single-product/tabs/description.php
, 并且您不能使用它添加产品免责声明。
Now the template single-product/tabs/description.php
use the_content()
Wordpress function to display the product description and you can add your disclaimer after it using the_content
filter hook this way: 现在,模板
single-product/tabs/description.php
使用the_content()
Wordpress函数来显示产品描述,您可以使用the_content
过滤器挂钩以以下方式添加免责声明:
add_filter( 'the_content', 'display_disclaimer_after_product_description', 10, 1 );
function display_disclaimer_after_product_description( $content ){
// Only for single product pages
if( ! is_product() ) return $content;
if( $product_disclaimer = get_field( 'product_disclaimer', get_the_id() ) )
return $content . '<b>Disclaimer:</b> ' . $product_disclaimer;
return $content;
}
Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 Tested and works.
经过测试和工作。
If you want to replace the product description with that disclaimer, you will replace this line: 如果要用该免责声明替换产品说明,则将以下行替换:
return $content . '<b>Disclaimer:</b> ' . $product_disclaimer;
by the following one: 通过以下之一:
return '<b>Disclaimer:</b> ' . $product_disclaimer;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.