• 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 12 replies - 16 through 27 (of 27 total)
  • Thread Starter matheny00

    (@matheny00)

    I think I know where the issue might be on your webpage click on the first item album. then look to the right of the picture that is the product short description
    Album
    $15.00

    “This is a simple, virtual product.”

    what is truncating is the first description and that one is not the one being feed to the home page.

    Thread Starter matheny00

    (@matheny00)

    ill be gone for a few hours will check back soon
    again thank you

    Stef

    (@serafinnyc)

    Ah I missed that. Sorry.

    
    add_action( 'woocommerce_after_shop_loop_item_title', 'description_in_shop_loop_item', 3 );
    function description_in_shop_loop_item()
    {
        global $post;
        
        $limit = 24; //number of characters
    
        $excerpt = $post->post_excerpt;
        if (str_word_count($excerpt, 0) > $limit) {
            $arr = str_word_count($excerpt, 2);
            $pos = array_keys($arr);
            $excerpt = substr($excerpt, 0, $pos[$limit]) . '';
        }
        echo '<span class="description"><p>' . $excerpt . '</p></span>';
    }
    
    • This reply was modified 5 years, 5 months ago by Stef.
    Thread Starter matheny00

    (@matheny00)

    ok that works part way it truncates but it duplicates the text if you look at the page you will see.

    Stef

    (@serafinnyc)

    Because you have the other snippet in there. Take it out. Only use my last snippet.

    Thread Starter matheny00

    (@matheny00)

    This is all I have added after the basic function.php file

    * Rename product data tabs
    */
    add_filter( ‘woocommerce_product_tabs’, ‘woo_rename_tabs’, 98 );
    function woo_rename_tabs( $tabs ) {

    $tabs[‘additional_information’][‘title’] = __( ‘Specification / More Info.’ ); // Rename the additional information tab

    return $tabs;

    }

    /**** truncate home page text */

    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘description_in_shop_loop_item’, 3 );
    function description_in_shop_loop_item()
    {
    global $post;

    $limit = 24; //number of characters

    $excerpt = $post->post_excerpt;
    if (str_word_count($excerpt, 0) > $limit) {
    $arr = str_word_count($excerpt, 2);
    $pos = array_keys($arr);
    $excerpt = substr($excerpt, 0, $pos[$limit]) . ”;
    }
    echo ‘<span class=”description”><p>’ . $excerpt . ‘</p></span>’;
    }

    Stef

    (@serafinnyc)

    Like i said earlier. You probably have a snippet somewhere else because natively the Storefront theme doesn’t show this. If you do, delete it. As well as clear cache or use a private browser.

    Thread Starter matheny00

    (@matheny00)

    there is no snippet it is loaded via the powerpack from woo so I might have to change the way I do my home page. Thank you very much I will keep working on this till I can get it the way I like it.

    If you have any opinion or suggestions on the site always open for direction. And again thank you

    Stef

    (@serafinnyc)

    Can’t you turn that portion off? I haven’t used it in awhile.

    Thread Starter matheny00

    (@matheny00)

    Yes just found it buried in the customizer.
    so how do I adjust to less text on the description? I would like to limit it to 2 lines of text if that is possible

    Thread Starter matheny00

    (@matheny00)

    I figured it out thank you the code said $limit = 25; //number of characters but it was words so I got it fixed.

    Thread Starter matheny00

    (@matheny00)

    It seems I have got all my questions figured out got lucky and found an article on the moving of the social media.
    Do you have a paypal account I would like to send you some cash as a thank you,

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