I'm using the following code on my WordPress site to shorten my description excerpt on WooCommerce and it works fine if I input my characters for 14 or less. As soon as I enter more than 14 characters it shows the full short description.
add_action( 'woocommerce_after_shop_loop_item_title', 'lk_woocommerce_product_excerpt', 35, 2);
if (!function_exists('lk_woocommerce_product_excerpt'))
{
function lk_woocommerce_product_excerpt()
{
$content_length = 14;
global $post;
$content = $post->post_excerpt;
$wordarray = explode(' ', $content, $content_length + 1);
if(count($wordarray) > $content_length) :
array_pop($wordarray);
array_push($wordarray, '...');
$content = implode(' ', $wordarray);
$content = force_balance_tags($content);
$content = substr($content, 0, 14);
endif;
echo "<span class='excerpt'><p>$content...</p></span>";
}
}
Any help would be appreciated.
Thank you.