Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display product description on WooCommerce shop/category pages
<?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);
@Ark74

This comment has been minimized.

Copy link

commented Apr 24, 2017

Hi,
I've been searching a way to show the product description formated with HTML on the product page.

Can i use this?

@zakirsajib

This comment has been minimized.

Copy link

commented Oct 10, 2017

Works perfectly.

@nerddigitalguy

This comment has been minimized.

Copy link

commented Nov 1, 2017

Thank you!!! This works perfectly, I just dropped it into my "themes/theme-name/functions.php".

@stephic

This comment has been minimized.

Copy link

commented Nov 2, 2017

Amazing. Thank you. Just curious, is there a way to limit the the amount of words?

@MetaeCC

This comment has been minimized.

Copy link

commented Nov 10, 2017

Hi everybody,
how can I "echo" only first <p class="myclass"> element contained inside the woocommerce_short_description?
I guess using something like $html->find('p.myclass[1] p') but how do I code it inside woocommerce_after_shop_loop_item_title_short_description function?
I'm not a coder at all, can someone help me please?
Many thanks :-)
Marcella

@strarsis

This comment has been minimized.

Copy link

commented Nov 29, 2017

I had to use echo $product->get_short_description() instead:

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);
@nikkles

This comment has been minimized.

Copy link

commented Feb 7, 2018

thank you, worked perfectly!

@GVSRSA

This comment has been minimized.

Copy link

commented Feb 20, 2018

I signed up just to say thank for this code. Exactly what I needed and worked perfectly first try.

THANK YOU!!

@m1l35

This comment has been minimized.

Copy link

commented Mar 11, 2018

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

@Manik013

This comment has been minimized.

Copy link

commented Mar 15, 2018

haha... thx a lot!

@Arlette12345

This comment has been minimized.

Copy link

commented May 5, 2018

This might be a stupid question, but how do you copy the code into the php file? I'm lost in wordpress

@rikuseo

This comment has been minimized.

Copy link

commented May 9, 2018

Wanted to know how to limit the number of words or lines which are included as well. My descriptions are too long to be show on shop page.
@stephic and @m1l35 wanted to know too.

@om4james please spare us your talent again !

@acia17

This comment has been minimized.

Copy link

commented May 29, 2018

Please help, i also need that code but for the related product post.
Can anyone please Help me.

@PATRICEINFORMATIQUE

This comment has been minimized.

Copy link

commented Jul 26, 2018

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 ?
Thanks

Patrice

@glownotes

This comment has been minimized.

Copy link

commented Jul 29, 2018

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!

@wmcstudios

This comment has been minimized.

Copy link

commented Aug 7, 2018

Works great, thank you!

@gjw66

This comment has been minimized.

Copy link

commented Aug 22, 2018

Hi, signed up to say thankyou for the code - worked great! But can the number of words/characters be limited?
thanks in advance

@innuvo

This comment has been minimized.

Copy link

commented Oct 4, 2018

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

@RJStomps

This comment has been minimized.

Copy link

commented Oct 29, 2018

Is it possible to show just the first 10 words or 75 characters

@twont

This comment has been minimized.

Copy link

commented Nov 11, 2018

@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

<div itemprop="description"> <?php echo substr(apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ),0,230); echo '...' ?> </div>

@techbase123

This comment has been minimized.

Copy link

commented Nov 28, 2018

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...

@klynn33

This comment has been minimized.

Copy link

commented Dec 7, 2018

@twont Thanks for the link - that code worked perfect.
I also commented on that page wondering...

The whole description displays as a clickable link? (I verified it wasn't the theme).
Also it's displaying the description before the title, instead of below in shop page?

Any fix for this? Thanks.

@Janoycresva

This comment has been minimized.

Copy link

commented Dec 10, 2018

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?

@davidrhoden

This comment has been minimized.

Copy link

commented Dec 12, 2018

strarsis' edit worked for me on WP 5.0.

@Djofferson

This comment has been minimized.

Copy link

commented Dec 22, 2018

Hi there,
I'm completely new to code. Did a little css but that's about it.
So I tried to copy and paste the code above into my WP Child theme's function.php but I got this message: https://cl.ly/a454b75c5e92
Scrape nonce check failed. Try again.
So I tried but nothing changed.
Do I need to open from ftp and change the functions.php with Brackets application?

This is what I'd like to achieve: https://cl.ly/7091fa8fab79

Kind regards,
Djofferson

@Djofferson

This comment has been minimized.

Copy link

commented Dec 22, 2018

Ok, and need to add that I'm working on a staging site...

@jquiros2

This comment has been minimized.

Copy link

commented Dec 28, 2018

Also worked on first try! Thank you... What would the css ref be, for styling the text?

@rafafeuer

This comment has been minimized.

Copy link

commented Feb 4, 2019

Any way I can do that with a custom taxonomy instead of the short description?

@CAT6e

This comment has been minimized.

Copy link

commented May 27, 2019

Works perfectly! Thank you ❤❤

@paradoxicalNL

This comment has been minimized.

Copy link

commented May 29, 2019

Thanks, very useful for me! Also added the height here so I keep my layout as I want.

@sergiconstance

This comment has been minimized.

Copy link

commented Jul 23, 2019

thank you, the code is working, i just it in funtion.php but the description is displayed on top of the image -

@abid112

This comment has been minimized.

Copy link

commented Aug 14, 2019

Worked perfectly! Thank you so much man! Appreciate your good work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.