dongtangze6393 2015-11-02 01:48
浏览 161

在Woocommerce产品页面描述之后添加文本/ HTML

I'm having issues concatenating text/html to the Woocommerce product page description based on the product's category.

I've added the following to my functions.php theme file:


    add_filter('woocommerce_short_description', 'caution_text');

    function caution_text($desc){
        if(is_product_category('stone')){
            $desc .= 'Text/HTML To Add';
        }
        return $desc;
    }

I've tried it both with and without the product category check and it still is not concatenating the text, so I'm inclined to think I've created my filter wrong.

For reference, I'm using the StoreFront theme with some custom modifications, none of which should be causing conflicts with this.

Any help is greatly appreciated!

Thank you!

  • 写回答

1条回答 默认 最新

  • dpthuyh1678 2015-11-02 02:30
    关注

    The code isn't working because is_product_category() checks whether you're viewing a product category. The code runs on the single product page therefore will always evaluate to false.

    Use has_term() instead.

    Replace:

    if(is_product_category('stone')){
    

    With:

    if ( has_term( 'stone', 'product_cat' ) ) {
    

    Further reading: https://codex.wordpress.org/Function_Reference/has_term

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度