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中实现的内容。显示文本,但我无法获得第二个函数输出 ($title(。
请问有人知道吗?
谢谢
woocommerce_template_single_title
对应的模板位于 WooCommerce 文件夹templates/single-product/title.php
,活动代码只有这一行:
the_title( '<h1 itemprop="name" class="product_title entry-title">', '</h1>' );
因此,您可以直接使用WordPress the_title()
功能,因为它已经回显,并且您实际上不需要第二个功能...但是如果你想在变量中设置它,你必须使用 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>' );
}
代码进入功能.php活动子主题(或主题(的文件或任何插件文件中。
此代码经过测试并有效。
$title
的赋值应在使用前完成。不要在回显语句中使用回显。那应该是这样的:
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;
}