Search code examples
phpwordpresstemplateswoocommercestring-concatenation

Append a text string to WooCommerce product title


<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


Solution

  • 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.