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:
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
Leave a Reply
You must be logged in to post a comment.
Instead of the filter you used, try the action ‘woocommerce_after_shop_loop_item_title’ this way
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