Menachem Menachem - 1 year ago 95
PHP Question

WooCommerce - How to limit the short product description

in WooCommerce, How can I limit the short product description in the shop page? i added this code:

add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5);

but can't limit it to 40 charachters.


Answer Source

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!)

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, 20);
    return $post_excerpt;

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

and use this line where you want to display product description -

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download