Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add content above the product short description on the product page in WooCommerce

I am looking for a way to insert a custom content between the product title and its short description on the product page in WooCommerce. So far I was only able to add a custom content at the beginning of the short description with the following code:

function insert_content( $post_excerpt )  {
      $content = 'My custom content';
       return $content.'<br>'.$post_excerpt; } 
add_filter('woocommerce_short_description', 'insert_content', 10, 1);

However, I need this content to be between the product title and the short description title, not below this last one. I guess I am using the wrong hook but the few others I've tried don't work. Any ideas?

like image 333
Adrien Avatar asked May 11 '17 18:05

Adrien


1 Answers

Look at the content-single-product.php template. You will see that the title and the short description are both attached to the woocommerce_single_product_summary hook with different priorities. If you want to insert content between them, add it to that hook with a priority that is in between the two values. The title is on 5 and the excerpt is on 20 so 15 would be between the two, but still after the price and the ratings.

function so_43922864_add_content(){
    echo 'TACOS!';
}
add_action( 'woocommerce_single_product_summary', 'so_43922864_add_content', 15 );
like image 77
helgatheviking Avatar answered Oct 17 '22 07:10

helgatheviking