Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Last active July 17, 2021 16:10
Show Gist options
  • Save tdmrhn/019beb7c929752594875b29a1b411366 to your computer and use it in GitHub Desktop.
Save tdmrhn/019beb7c929752594875b29a1b411366 to your computer and use it in GitHub Desktop.
Add Description to Product Card
<?php
add_action('woocommerce_after_shop_loop_item_title', 'add_description_to_product_card', 3 );
function add_description_to_product_card() {
global $product;
$limit = 10;
$description = $product->get_description();
if (str_word_count($description, 0) > $limit) {
$words = str_word_count($description, 2);
$pos = array_keys($words);
$excerpt = substr($description, 0, $pos[$limit]) . '...';
} else {
$excerpt = $description;
}
echo '<p class="description">'.$excerpt.'</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment