• I am using woocommerce storefront with power pack and have talked to their support with no luck on this issue. On the home page woocommerce feeds in multiple topics and products and i like that what I do not like is the fact that the short description is so long making the page much longer than needs to be. I would like to truncate that text to 2 lines or so many words, letters etc…
    I have had no luck with everything on line so hope someone here can help.
    Thank you

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 27 total)
  • Stef

    (@serafinnyc)

    You could add this to your functions file of your child theme.

    function description_in_shop_loop_item() {
        global $product;
    
        $limit = 35; //number of characters
    
        $description = $product->get_description(); 
           if (strlen($description) > $limit) {
    $excerpt = substr($description, 0, $limit) . '...';
           
                   } else {
           
           $excerpt = $description;
        }
        echo '<p class="description">'.$excerpt.'</p>';
    }
    Thread Starter matheny00

    (@matheny00)

    Stef thanks where would I add it in the child theme? in the functions.php of the child theme?

    Stef

    (@serafinnyc)

    Take a screenshot of your functions file use something like imgur or snag.gy to post to

    You want to add it right after the

    <?php

    Or at the very bottom. It depends. Some themes have nothing in their functions folders nowadays.

    • This reply was modified 5 years, 5 months ago by Stef.
    Thread Starter matheny00

    (@matheny00)

    Here it is I added it at the bottom but it did nothing

    View post on imgur.com

    Stef

    (@serafinnyc)

    Looks good. Although I never advise editing in the Theme Editor. Always try and use SFTP/FTP when you can.

    Thread Starter matheny00

    (@matheny00)

    oh ok new to all this… so it is in place but the text is not being shortened/truncated on the home page

    View post on imgur.com

    Stef

    (@serafinnyc)

    You have to clear your cache every time you add code or do file edits.

    Open in a private browser if you don’t know how to clear cache

    Thread Starter matheny00

    (@matheny00)

    I did clear cache and tested in firefox and chrome plus incognito window still shows full text

    Stef

    (@serafinnyc)

    You sure you added it to the Storefront theme and not the TwentyNineteen theme? All the more reason to learn SFTP/FTP.

    Look at the Drop Down when in Theme Editor to the right. Make sure Storefront Child is selected. Make sure you also have the latest Storefront installed.

    Powerpack maybe blocking it but I doubt it. Tested on mine and it works.

    Thread Starter matheny00

    (@matheny00)

    yes if you look at the first picture I sent it also confirms the child theme is active and I just viewed the ftp file and it is correct

    Stef

    (@serafinnyc)

    How are you achieving the short description on that page? Shortcode?

    Thread Starter matheny00

    (@matheny00)

    no it is feed in from woocommece storefront automatically it is an option to select

    Stef

    (@serafinnyc)

    The only thing I think it could be is you copied it and your computer changed the quotes. Meaning it reformatted the ‘ character

    I have it working on my demo site using all: recent, best selling, featured, etc.

    • This reply was modified 5 years, 5 months ago by Stef.
    Stef

    (@serafinnyc)

    Also, if you used a snippet to add the short description to these you’ll need to remove it because by default this is not part of the theme. My code takes care of both.

    Thread Starter matheny00

    (@matheny00)

    ok ill go to the file direct and type your text into it and ftp it. the test comes from the short description page for the product direct.
    thank you

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Truncating text’ is closed to new replies.