Search code examples
phpwordpresswoocommercehook-woocommercecode-snippets

Add shortcode to WooCommerce product description


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?


Solution

  • 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