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.

9 Comments

  1. RJ on February 17, 2021 at 9:06 am

    The code works for me, but I want to have a href tag added in the more where once clicked it will redirect to the product page to view the full description of the product base on the woo description showing.
    Example 1
    $more = ‘. . . READ MORE ‘;

    Example2 (here I want it to be dynamic not defined ID for the product)
    $more = ‘. . . READ MORE ‘; // add a more cta

    Please let me know what to add in the code to make it dynamic.

  2. Mirko on August 17, 2020 at 3:26 pm

    the code works in the length of the text, but undoes the previous formatting. Has anyone solved this problem?

  3. Jasper on July 10, 2020 at 6:20 am

    This code works on `is_product_category` product category page using that conditional where we show products with excerpts:

    “`
    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…
    global $post;
    if( is_product_category() ) { // add in conditionals);
    $text = $post_post_excerpt;
    $words = 38; // change word length
    $more = ‘ […]’; // add a more cta

    $post_post_excerpt = wp_trim_words( $text, $words, $more );
    }

    return $post_post_excerpt;

    };
    “`
    But somehow it also shortens the category description / term description at the top as well. Any ideas how to get around that?

    • Gorka on November 11, 2020 at 8:20 am

      hi Jasper,

      Seem problem here. It also shortens the category description, did you find a workaround?

  4. Nikos on May 1, 2020 at 12:24 pm

    Hi there!
    I am not expert, so please if you can,
    tell me where I must paste this code to get the results.

    Thank you!
    Nikos

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

    • Dani on September 8, 2021 at 2:02 pm

      I have the same problem

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

    thanks code work.

    How to put a limit on related products ?

Leave all Comment