<div class="woocommerce-loop-product__title"><? wc_get_template('single-product/title.php');?>
Im trying to make this string say: "Product Name More Info"
I can get the Product Name part fine, but how do i concatenate the 'more info' to this code to make it output correctly? Every echo attempt i try breaks my site
If you look to the template single-product/title.php
code you have essentially just this:
the_title( '<h1 class="product_title entry-title">', '</h1>' );
The WordPress function the_title()
echoes the product title, so you can't use echo again if you want to append "More Info" to the title. You will use this line instead:
<div class="woocommerce-loop-product__title"><? the_title( '<h1 class="product_title entry-title">', ' More Info</h1>' ); ?>
or in a more cleaner way.
<div class="woocommerce-loop-product__title"><? the_title( '<h1 class="product_title entry-title">', ' '. __("More Info") . '</h1>' ); ?>
Tested and works.
If you are trying to concatinate product name title with a string, then you can use the woocommerce_shop_loop_item_title
hook.
remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
function change_product_title() {
$additional_text = ' More info';
echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() .$additional_text.'</h2>';
}
add_action('woocommerce_shop_loop_item_title','change_product_title');
Or if you want to change the title of product in single product page then,
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
function woocommerce_template_single_title_custom(){
$additional_text = ' More Info';
the_title( '<h3 class="product_title entry-title">', $additional_text.'</h3>' );
}
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title_custom', 5);
Where the syntax for the_title
function is
the_title( $before, $after, $echo );