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.