Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1068041

    Hi,

    I’m using this code to display short description on the shop page
    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_single_excerpt’, 5);

    How can make it so that their is a limit as to how much short description shows on the shop page around 2 lines or something?

    Thanks
    Zak

    #1068393

    Hey Zak,

    Please share the woocommerce_template_single_excerpt function, it is the one that can be used to work with the excerpt length.

    Best regards,
    Victoria

    #1069144

    Hi Victoria,

    Im assuming its this:
    if ( ! function_exists( ‘woocommerce_template_single_excerpt’ ) ) {

    /**
    * Output the product short description (excerpt).
    */
    function woocommerce_template_single_excerpt() {
    wc_get_template( ‘single-product/short-description.php’ );
    }
    }

    Apologies if I got the incorrect part.
    FYI I added this code: add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_single_excerpt’, 5); – in the child theme functions.php.

    Thanks
    Zak

    #1069434

    Hi Zak,

    Here is the code you can put in your funtions.php

    
    add_filter('woocommerce_short_description','avia_change_wc_description', 10, 1);
    function avia_change_wc_description($length)
    {
       $length = 100;
       return $length;
    }
    

    If you need further assistance please let us know.

    Best regards,
    Victoria

    #1069724

    Hi Victoria,

    Unfortunately, that does not work. It basically removes the text and instead says “100” under each product.

    Thanks
    Zak

    #1070796

    Hi,

    I’ve got the short description working using the following code:

    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, 18));

    }
    return $post_excerpt;
    }

    Is it possible to add ‘…’ after the sentences?

    Thanks
    Zak

    #1071359

    Hi Zak,

    Glad you got it working for you and thank you for sharing your solution! :)

    If you need further assistance please let us know.

    Best regards,
    Victoria

    #1071524

    Hi Victoria,

    One last question.

    Is it possible end the sentences with “…”? What code would I need to add to the current code?

    Thanks
    Zaki

    #1073082

    Hi Zaki,

    Try the return statement like this

    
    return "{$post_excerpt}...";
    

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1073093

    Hi Victoria,

    Thank you so much!

    You can close this thread

    Best Regards
    Zak

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Woocommerce short description limit’ is closed to new replies.