Skip to content

Limit the Words in WooCommerce Product Short Description

WooCommerce has a filter that can limit the words in a product short description field  called ‘woocommerce_short_description‘ – coupled with an existing WordPress function ‘wp_trim_words‘ we can make the description any length to suit teasers, sliders etc and leave other areas where we want the full short description.

In the code snippet above we are using a conditional to apply this to any usage of the short description outside of a single product post, the filter uses the 1 parameter $post_post_excerpt which is assigned to $text, the $word count is set to 10 with a […] used as the $more valuethese three parameters belong to wp_trim_words which is executed and returned back to $post_post_excerpt – which is now a 10 word product short description.

Nifty.

2 Comments

  1. Leon on October 2, 2019 at 4:18 am

    Code is great but not working entirely. Words are cut correctly but MORE function doesn’t work.

    $more = ‘ […]’; // add a more cta

    Will just add […] at the end of a product description. There’s no “more” call to action or anything. Tested with latest woocommerce 3.7

    Any chance to correct code?

  2. buran on June 2, 2019 at 7:48 am

    thanks code work.

    How to put a limit on related products ?

Leave a Comment





Scroll To Top