Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php // <~ don't add me in
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;
};
@TheWatUpDude
Copy link

TheWatUpDude commented Mar 6, 2021

Implemented this and still nada. Do we have to add something to the short code?

@neilgee
Copy link
Author

neilgee commented Mar 9, 2021

Still works, it’s not a short code though, code goes in functions file and template conditions need to be set as commented in code.

@AnhDOS
Copy link

AnhDOS commented Jul 22, 2021

This doesn't work for me. I use this instead

@beshealthcare
Copy link

beshealthcare commented Apr 22, 2022

This works, but it also limits the description on the category description on product category listing pages. How do I prevent this?

@beshealthcare
Copy link

beshealthcare commented Apr 22, 2022

I also just noticed that the function doesn't get applied to post items in loops outside the main loop e.g. 'related products' or 'recently viewed'. How could I apply it to them too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment