简体   繁体   English

在Woocommerce中在产品描述之后显示自定义字段

[英]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 template single-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.

相关问题 在 Woocommerce 单个产品页面的简短描述下显示自定义字段 - Display a custom field under short description in Woocommerce single product pages 在 WooCommerce 产品描述选项卡中保存并显示自定义字段 - Save and display a custom field in WooCommerce product description tab 在Woocommerce中的产品简短描述后显示自定义字段值 - Displaying custom field values after product short description in Woocommerce 在Woocommerce中查找并​​显示产品自定义字段值 - Find and display a product custom field value in Woocommerce 在 WooCommerce 产品变体中显示 ACF 自定义字段 - Display ACF custom field in WooCommerce product variations 如何在 WooCommerce 中显示产品自定义字段值? - How display a product custom field value in WooCommerce? 产品描述在特征图片后没有显示 - woocommerce 商店 - product description is not getting display after feature image - woocommerce shop 在Woocommerce中将产品描述简短描述后移动 - Move product description after short description in Woocommerce 在Woocommerce单个产品页面中显示高于产品价格的自定义字段 - Display a custom field above product price in Woocommerce single product pages 显示自定义字段吹产品标题Woocommerce产品单页 - Display custom field blow product title Woocommerce product single pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM