0
votes

In a WordPress woocommerce template, this line outputs woocomerce product description / excerpt

<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>

Adding my HTML after that line outputs my HTML outside the div that holds the excerpt/description of the product. I am trying to add a div inside the content as if it was added in the editor.

Basically, I want to add something in all products but because I have many products already, I want a way to insert it in template file or something just once and applied to all.

Anyone know how can I do that?

2

2 Answers

0
votes

You could add a filter that adds the div, before the woocommerce software adds it. Try something like this, inside your <theme>/functions.php file:

function add_my_div($desc) {
  return '<div class="my-div">'.$desc.'</div>';
}
add_filter('woocommerce_short_description', 'add_my_div', 0, 1);

Notice it is on priority 0. This should run before most other filters. The default value for priority is 10, and I am pretty sure that is the priority that WC adds it's wrapper div.

Hope this helps.

0
votes

jquery .append did the trick for me

http://api.jquery.com/append/

@loushou Thanks for your comment. It looks like your suggestion could work also but I haven/t tried it yet. Will do If I got the time and update my findings here.

Thanks