In Woocommerce product single pages, the long description is displayed in the "description tab". If you look at the source code of single-product/tabs/description.php
template, it use the_content()
wordpress function to display that long description.
So you can use the_content
dedicated Wordpress filter hook to reduce the product long description:
add_filter( 'the_content', 'shorten_product_long_descrition', 20 );
function shorten_product_long_descrition( $content ){
// Only for single product pages
if( ! is_product() ) return $content;
// Set the limit of words
$limit = 14;
if (str_word_count($content, 0) > $limit) {
$arr = str_word_count($content, 2);
$pos = array_keys($arr);
$text = '<p>' . substr($content, 0, $pos[$limit]) . '...</p>';
$content = force_balance_tags($text); // needded
}
return $content;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Before:
After:
Similar: Limit product short description length in Woocommerce
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…