Last active
April 1, 2024 19:21
-
-
Save thejamescollins/9883140 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 apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ) ?> | |
</div> | |
<?php | |
} | |
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5); |
kentunetexas
commented
Jun 3, 2021
via email
I didn't.
…On Tue, Jun 1, 2021 at 11:55 PM scaliebloke ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi,
I am also looking for what kentunetexas is looking for
This worked great, BUT.... can someone help me figure out how to only show
the short description for certain product categories?
Hey mate, did you ever find a solution to this at all?
Kind regards.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/9883140#gistcomment-3765790>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AS7WWJE7GKC2RF6LLZIJHZ3TQW2VJANCNFSM4HPZAE2A>
.
Hello all. There is one issue with this code. If I format the short description text in the product page, it will be formatted on Shop page as well.
Could anyone help me to keep the text on shop page unformatted?
Thanks @mrwweb . Works well on the category page. Only description we use are rather long so will need to shorten them some with something like
add_filter( 'woocommerce_short_description', 'prefix_filter_woocommerce_short_description' ); /** * Limit WooCommerce Short Description Field */ function prefix_filter_woocommerce_short_description( $post_post_excerpt ) { // make filter magic happen here... if(! is_product() ) { // add in conditionals $text = $post_post_excerpt; $words = 10; // change word length $more = ' […]'; // add a more cta $post_post_excerpt = wp_trim_words( $text, $words, $more ); } return $post_post_excerpt; };
as shared by Neil Gee https://gist.github.com/neilgee/c0834345db048429e3efb8ff47e3478d#file-get-shorty-php
This doesn't work to me. The code of @mrwweb work.
This works perfectly in functions.php
What if I would like to filter only the first paragraph of the short description instead of trim words?
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment