I edited my Child Theme's functions.php to display the short description of my WooCommerce products under the product title.
I had this code that works fine and limits the number of characters to 165, then adds "..." at the end of the excerpt. However, I don't want the words to break after 165 characters. Therefore, I was wondering if there was a way to either limit the number of words instead of character, or simply keep the words from breaking?
function woocommerce_after_shop_loop_item_title_short_description() {
global $product;
if ( ! $product->post->post_excerpt ) return;
?>
<div itemprop="description">
<?php echo substr(apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ),0,165);
echo '...'
?>
</div>
<?php
}
source https://stackoverflow.com/questions/69002775/limit-number-of-words-in-woocommerce-description-using-php
Comments
Post a Comment