Add shortcode to WooCommerce product description

Viewed 326

I am trying to auto-add some shortcode at the end of every woo product description. (not after short description). The code with which I am trying is:

add_filter('product_descr','ce_add_text_short_descr');
function ce_add_text_short_descr($description){
$text="[my-shortcode-goes-here]";
return $description.$text;
}

That one is not working for me. can someone help me?

2 Answers
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
   $text = do_shortcode('[my-custom-text]');
  return $description.$text;
}

You are making mistake with woocommerce hook and if we neeed to print a shortcode in a php file it works with do_shortcode(); Hope it will work on your side I have already tested it. Don't forget to replace my-custom-text with your shortcode.

add_filter('the_content', 'mujuonly_alter_product_description');

function mujuonly_alter_product_description($description) {
    if (is_product()) {
        $text = do_shortcode('[products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true" ]');
        return $description . $text;
    }
  return $description;
}

This way using the hook the_content you can update the product description using the shortcode

Related