duancan1950 2017-04-05 16:15
浏览 5

如何在php中实现第二个功能

add_action( 'woocommerce_after_single_product_summary', 'show_text', 5 );

 function show_text() {
echo "Buy this from our store. This is the best (echo $title) in the industry. By using this (echo $title) you save more.";

$tittle = woocommerce_template_single_title();
echo $tittle; 
}

This is what I try to implement in WooCommerce below my products. The text is displayed, but I can't get the second function output ($title).

Anyone has any idea please?

Thanks

  • 写回答

2条回答 默认 最新

  • doq91130 2017-04-05 20:45
    关注

    The corresponding template for woocommerce_template_single_title is located in the WooCommerce folder templates/single-product/title.php and the active code is just this line:

    the_title( '<h1 itemprop="name" class="product_title entry-title">', '</h1>' );
    

    So you can use the_title() WordPress function directly as it's already echoed and you don't really need a second function… But if you want to set it in a variable you have to use instead get_the_title().

    So your code will be something like:

    add_action( 'woocommerce_after_single_product_summary', 'show_text', 5 );
    function show_text() {
    
        $title = get_the_title();
        echo "<p>Buy this from our store. This is the best $title in the industry. By using this $title you save more.</p>";
    
        // Optional - Displaying title directly (without echo)
        the_title( '<h1 itemprop="name" class="product_title entry-title">', '</h1>' );
    }
    

    The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    This code is tested and works.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b