set the limit of the short description on the related product list

I need to set the limit of the short description on the related product list.

I have done this for the product list page by using the filter:

Read More
function my_filter_woocommerce_short_description( $post_excerpt )   {

    if(is_product()){


    }else{
             $post_excerpt = get_the_content();
$post_excerpt = preg_replace(" ([.*?])",'',$post_excerpt);
$post_excerpt = strip_shortcodes($post_excerpt);
$post_excerpt = strip_tags($post_excerpt);
$post_excerpt = substr($post_excerpt, 0, 265);
$post_excerpt = substr($post_excerpt, 0, strripos($post_excerpt, " "));
$post_excerpt = trim(preg_replace( '/s+/', ' ', $post_excerpt));
$post_excerpt = $post_excerpt.'... <a href="'.get_permalink( $product_id ).'">more</a>';

             //$post_excerpt=substr($post_excerpt , 0 ,265);
        return $post_excerpt.'...';
    }
}
add_filter( 'woocommerce_short_description','my_filter_woocommerce_short_description',10, 2 );

however I need to display the full short description in the product page, so inside this filter I created a if is product.
The problem is inside product page I also have a list of related products which I need to display in a short way as it is being displayed in the product list page.

How can i do it?

Thank you

Related posts

Leave a Reply

1 comment

  1. Instead of the filter you used, try the action ‘woocommerce_after_shop_loop_item_title’ this way

    add_action('woocommerce_after_shop_loop_item_title','short_description_content', 5);
    
    function short_description_content(){
        //code for short description content
    }
    

    This way, you don’t need to check if it is single product or product list.

    To show short description in the related product list as you said, just add ‘the_excerpt’ in the above function

    function short_description_content(){
        the_excerpt();
    }