Woocommerce Product Excerpt in Category Page

This topic has 4 replies, 2 voices, and was last updated 6 years, 8 months ago ago by Rose Tyler

  • Avatar: Marta Iraola
    Marta Iraola
    Participant
    April 11, 2018 at 18:18

    Hello,

    As the title says, I would like to display the product short description or a custom field I created in each of the products in the category page. Currently the product grid only shows the Featured Image and the product Title.

    I have been searching online and I found some code for function.php but they don’t work in my site. For example this one:

    add_action('woocommerce_after_shop_loop_item_title', 'description_in_shop_loop_item', 3 );
    function description_in_shop_loop_item() {
        global $product;
    
        // HERE define the number of words
        $limit = 10;
    
        $description = $product->get_description(); // Product description
        // or
        // $description = $product->get_short_description(); // Product short description
    
        // Limit the words length
        if (str_word_count($description, 0) > $limit) {
            $words = str_word_count($description, 2);
            $pos = array_keys($words);
            $excerpt = substr($description, 0, $pos[$limit]) . '...';
        } else {
            $excerpt = $description;
        }
    
        echo '<p class="description">'.$excerpt.'</p>';
    }

    Is there any way to make it work? Or maybe you know about a plugin to achieve this?

    I will give you access to my site in Private content in case that helps.

    Thanks a lot for your help.

    Kind regards

    Please, contact administrator
    for this information.
    3 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 12, 2018 at 07:55

    Hello,

    Please note that additional customizations are not covered under our Support Policy. But we’ve made it for you (woocommerce folder in the child theme – content-product.php and content-product-slider.php files).
    Please check.

    Regards

    Avatar: Marta Iraola
    Marta Iraola
    Participant
    April 12, 2018 at 10:42

    Hi Rose,

    It is exactly what I wanted!

    Thanks a lot for your help. 😀

    Kind regards,

    Marta

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 12, 2018 at 10:44

    You’re welcome!
    Would you mind to rate our product:
    https://themeforest.net/downloads
    That would be much appreciated 🙂

    Regards

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.