I am trying to limit the number of words of the product category description in woocommerce on the product category page and add a read more link to expand the text. I have been trying to edit a product description character limit with no luck. Any help would be greatly appreciated. Here is the code i have been editing in the functions.php:
add_action('woocommerce_product_archive_description', 'description_in_shop_loop_item', 3 );
function description_in_shop_loop_item() {
global $shop_page;
// HERE define the number of characters
$limit = 75;
$description = $shop_page->post_content; // category description
// Limit the characters length
if (strlen($description) > $limit) {
$excerpt = substr($description, 0, $limit) . '...';
} else {
$excerpt = $description;
}
echo '<p class="description">'.$excerpt.'</p>';
}
2
Answers
You could use some jQuery to shrink the height of the description container and add a ‘Read more’ button that will resize the container back to its original height.
This is how I implemented on my website. Thanks Terminator-barbapapa