2017-04-05 258 views
1
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; 
} 

第二功能这是我尝试在WooCommerce实现我的产品之下。文本显示,但我不能得到第二个功能输出($标题)。如何在PHP中实现

任何人有任何想法吗?

感谢

+0

'var_dump($ tittle);'return? –

回答

1

woocommerce_template_single_title相应的模板位于WooCommerce文件夹templates/single-product/title.php和有源代码只是这一行:

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

这样你就可以直接使用the_title() WordPress的功能它已经被回显,你并不需要第二个功能......但是如果你想将它设置在一个变量中,你必须使用get_the_title()

所以,你的代码将是这样的:

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>'); 
} 

的代码放在你的活跃儿童主题(或主题)的function.php文件或也以任何插件文件。

该代码测试和工程。

分配的 $title
0

变量应该使用。请不要使用echo回声statements.That应该像之前完成:

add_action('woocommerce_after_single_product_summary', 'show_text', 5);  
    function show_text() {  
    $tittle = woocommerce_template_single_title(); 
    echo "Buy this from our store. This is the best $title in the industry. By using this $title you save more."; 
    echo $tittle; 
} 

============== ================================================== ========

如果woocommerce_template_single_title()不起作用。然后使用get_the_title() function.eg。

add_action('woocommerce_after_single_product_summary', 'show_text', 5); 
function show_text() { 
    $tittle = get_the_title(); 
    echo "Buy this from our store. This is the best $title in the industry. By using this $title you save more."; 
echo $tittle; 
}