-
-
Save twont/eb15fd4d71fe9153641d0373150b9b72 to your computer and use it in GitHub Desktop.
Display product description on WooCommerce shop/category pages
This file contains 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 the product's short description (excerpt) to the WooCommerce shop/category pages. The description displays after the product's name, but before the product's price. | |
* | |
* Ref: https://gist.github.com/om4james/9883140 | |
* | |
* Put this snippet into a child theme's functions.php file | |
*/ | |
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,230); | |
echo '...' | |
?> | |
</div> | |
<?php | |
} | |
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hy,
I don't know why but if the text does not reach the character limit we set, the ellipsis will be there at a fixed point. I assume we should make an if statement that makes the ellispsis only if the text exceeds the character limit. Can you help me with that?