Woocommerce Short Description Excerpt Length

I’m trying to change the Short Description excerpt length.

I found a previous post stating that I should change

Read More
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>

to

<?php $excerpt = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
    echo substr($length,0, 10);
?>

However when doing that, my excerpts simply disappear.

Related posts

2 comments

  1. I’m afraid you’re editing the plugin… if that’s so, you’re doing it wrong..

    create a function and then hook to that filter… something like this…

    add_filter('woocommerce_short_description', 'reigel_woocommerce_short_description', 10, 1);
    function reigel_woocommerce_short_description($post_excerpt){
        if (!is_product()) {
            $post_excerpt = substr($post_excerpt, 0, 10);
        }
        return $post_excerpt;
    }
    

    paste this on your functions.php file of your theme.

  2. Instead of editing files directly within the plugin (which is a very bad idea because once update the plugin and all of your changes will be lost!)

    You can use this code for limit no of words

    add_filter('woocommerce_short_description', 'limit_woocommerce_short_description', 10, 1);
        function limit_woocommerce_short_description($post_excerpt){
            if (!is_product()) {
                $pieces = explode(" ", $post_excerpt);
                $post_excerpt = implode(" ", array_splice($pieces, 0, 20));
    
            }
            return $post_excerpt;
        }
    

    explode breaks the original string into an array of words, array_splice lets you get certain ranges of those words, and then implode combines the ranges back together into single strings.

    use this code to change Limit on the Shop Page not Product-detailed Page.

Comments are closed.