2017-04-05 647 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; 
}