Last active
July 17, 2021 16:10
-
-
Save tdmrhn/019beb7c929752594875b29a1b411366 to your computer and use it in GitHub Desktop.
Add Description to Product Card
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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