<?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); |
This comment has been minimized.
This comment has been minimized.
Works perfectly. |
This comment has been minimized.
This comment has been minimized.
Thank you!!! This works perfectly, I just dropped it into my "themes/theme-name/functions.php". |
This comment has been minimized.
This comment has been minimized.
Amazing. Thank you. Just curious, is there a way to limit the the amount of words? |
This comment has been minimized.
This comment has been minimized.
Hi everybody, |
This comment has been minimized.
This comment has been minimized.
I had to use function woocommerce_after_shop_loop_item_title_short_description() {
global $product;
if ( ! $product->get_short_description() ) return;
?>
<div itemprop="description">
<?php echo apply_filters( 'woocommerce_short_description', $product->get_short_description() ) ?>
</div>
<?php
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5); |
This comment has been minimized.
This comment has been minimized.
thank you, worked perfectly! |
This comment has been minimized.
This comment has been minimized.
I signed up just to say thank for this code. Exactly what I needed and worked perfectly first try. THANK YOU!! |
This comment has been minimized.
This comment has been minimized.
This is fantastic, thank you! Is there any way to limit the number of words or lines which are included? My Short descriptions are too long to all be placed there :( @stephic wants to know this too |
This comment has been minimized.
This comment has been minimized.
haha... thx a lot! |
This comment has been minimized.
This comment has been minimized.
This might be a stupid question, but how do you copy the code into the php file? I'm lost in wordpress |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Please help, i also need that code but for the related product post. |
This comment has been minimized.
This comment has been minimized.
Just a question about your good tip, how can i change the display result with css because i can't find with the inspector a css id ? Patrice |
This comment has been minimized.
This comment has been minimized.
Hey! Does anyone know how to change the alignment of the short description, now that it's under our product on the category page? I would like my text centered under my item, but I'd like the alignment to be justified- or at least left-aligned! |
This comment has been minimized.
This comment has been minimized.
Works great, thank you! |
This comment has been minimized.
This comment has been minimized.
Hi, signed up to say thankyou for the code - worked great! But can the number of words/characters be limited? |
This comment has been minimized.
This comment has been minimized.
Thanks for this, it works great! Is there a way to set this to only appear for one particular category page? Rather than all categories? Thanks |
This comment has been minimized.
This comment has been minimized.
Is it possible to show just the first 10 words or 75 characters |
This comment has been minimized.
This comment has been minimized.
@RJStomps @gjw66 @rikuseo @stephic @m1l35 To limit the description length you will need to use a substr. I have given an example that will limit to first 230 characters below. It will also add '...' on to the end of the text. Credits also to: @amanhstu https://gist.github.com/twont/eb15fd4d71fe9153641d0373150b9b72
|
This comment has been minimized.
This comment has been minimized.
Thank you for this solution! Works great at my product list: https://iiot-shop.com/products/ Is it possible to display the description in featured products, for example at homepage or custom product sliders, like here: https://iiot-shop.com/ These feeds must be generated in a different way... |
This comment has been minimized.
This comment has been minimized.
@twont Thanks for the link - that code worked perfect. The whole description displays as a clickable link? (I verified it wasn't the theme). Any fix for this? Thanks. |
This comment has been minimized.
This comment has been minimized.
Hi! For some reason the short description displays above the product picture, and not below the product name as I would like to have it. Any idea? |
This comment has been minimized.
This comment has been minimized.
strarsis' edit worked for me on WP 5.0. |
This comment has been minimized.
This comment has been minimized.
Hi there, This is what I'd like to achieve: https://cl.ly/7091fa8fab79 Kind regards, |
This comment has been minimized.
This comment has been minimized.
Ok, and need to add that I'm working on a staging site... |
This comment has been minimized.
This comment has been minimized.
Also worked on first try! Thank you... What would the css ref be, for styling the text? |
This comment has been minimized.
This comment has been minimized.
Any way I can do that with a custom taxonomy instead of the short description? |
This comment has been minimized.
This comment has been minimized.
Works perfectly! Thank you |
This comment has been minimized.
This comment has been minimized.
Thanks, very useful for me! Also added the height here so I keep my layout as I want. |
This comment has been minimized.
This comment has been minimized.
thank you, the code is working, i just it in funtion.php but the description is displayed on top of the image - |
This comment has been minimized.
This comment has been minimized.
Worked perfectly! Thank you so much man! Appreciate your good work. |
This comment has been minimized.
This comment has been minimized.
Where do I want to learn things like this? |
This comment has been minimized.
This comment has been minimized.
Anyone know how to make the comment area be within a set height colored box? My client has descriptions that are all different lengths but they want the descriptions to look uniform |
This comment has been minimized.
This comment has been minimized.
Hi kirstenvh32 - I am assuming you mean the short description area below your product on the shop page. It will depend on your theme somewhat how that box is determined but some css code I have used to equalise column heights is below. You need to add it to your child theme css code. .product_item a.product_item_link { .archive .product_item a.product_item_link img { The second piece of code helps align products without images. You may need to adjust the numbers depending how long your short description is. You can also sometimes add your own classes or styles to change font size, etc but that also varies according to your theme. In this case if you are relatively confident not to break code you could add a class in the code that changes the description in this section e.g. And then style .myownclass in your child theme css file. Give it a try anyway. |
This comment has been minimized.
This comment has been minimized.
Thank you very much |
This comment has been minimized.
This comment has been minimized.
This is exactly what I have been looking for, however, is there a way to tweak it a bit so that the description text is not part of the link (rather, just regular text) and perhaps add a bit of spacing between the product title and this? Also, a way to edit the description font size a bit so it doesn't look like a long product title? |
This comment has been minimized.
This comment has been minimized.
Notes: This now throws an error because the $product global isn't intended to be accessed directly. Using @moving900 The Here was my final code: <?php
function woocommerce_after_shop_loop_item_title_short_description() {
if ( has_excerpt() ) :
?>
<div itemprop="description">
<?php echo apply_filters( 'woocommerce_short_description', get_the_excerpt() ) ?>
</div>
<?php
endif;
}
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_after_shop_loop_item_title_short_description', 5 ); |
This comment has been minimized.
This comment has been minimized.
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 comment has been minimized.
This comment has been minimized.
Using get_the_excerpt() will eliminates the "Product properties should not be accessed directly" error. |
This comment has been minimized.
This comment has been minimized.
Hi! |
This comment has been minimized.
This comment has been minimized.
thanks a lot |
This comment has been minimized.
This comment has been minimized.
Thanks om4james, it works perfectly |
This comment has been minimized.
This comment has been minimized.
Hi everyone. |
This comment has been minimized.
This comment has been minimized.
This worked great, BUT.... can someone help me figure out how to only show the short description for certain product categories? |
This comment has been minimized.
Hi,
I've been searching a way to show the product description formated with HTML on the product page.
Can i use this?