How to insert ‘…’ after shortened woocommerce product titles? (php) [duplicate]

  php, woocommerce, wordpress

I have a PHP code that allowed me to limit my woocommerce product titles to 120 characters. This works perfectly, however, I would also like to insert three dots after the shortened title as an indicator the title continues.

This is the code I am currently using:

add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
function shorten_woo_product_title( $title, $id ) {
    if ( ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' ) {
        return substr( $title, 0, 120); 
    } else {
        return $title;
    }
}

Could you please advise me what to add to this code to those three dots to appear as well?

See below a before-after of what the title currently looks like and what I would like to achieve:
https://i.stack.imgur.com/9s0BQ.jpg

Thank you in advance for your help.

Nora

The original code was from: https://thembay.com/

Source: Ask PHP

LEAVE A COMMENT