Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Claudio Sanches

    (@claudiosanches)

    You can use the follow code in your theme’s functions.php or writing a custom plugin to achieve it:

    function my_custom_wc_products_title( $title ) {
    	if ( is_product_category() ) {
    		return wp_trim_words( $title, 5, '...' );
    	}
    
    	return $title;
    }
    
    add_filter( 'the_title', 'my_custom_wc_products_title' );
    

    Check the docs for wp_trim_words(): https://codex.www.ads-software.com/Function_Reference/wp_trim_words

    Good luck.

    Thread Starter mingjie0409

    (@mingjie0409)

    @claudio Sanches

    HI Claudio Sanches

    thanks for your reply , and How could I change the code ? If I want to short WooCommerce products title in Shop page & category pages & product tags pages ?

    Is it possible ?

    Thanks

    JK

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    Just use the WoooCommerce conditional functions: https://docs.woothemes.com/document/conditional-tags/

    Thread Starter mingjie0409

    (@mingjie0409)

    I have these code work for me now :

    // Limit all WooCommerce product titles to max number of characters
    add_filter( ‘the_title’, ‘shorten_woo_product_title’, 10, 2 );
    function shorten_woo_product_title( $title, $id ) {
    if ( is_product_category() && get_post_type( $id ) === ‘product’ ) {
    return substr( $title, 0, 80 ); // change last number to the number of characters you want
    } else {
    return $title;
    }
    }

    But how to add WoooCommerce conditional functions to above code ?

    Is the below right : change this line ?
    if ( is_shop() & is_product_category() && get_post_type( $id ) === ‘product’ ) {

    Please advance … Thanks

    JK

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Yes that looks correct, but if you need help adding and customising these snippets further please consider jobs.wordpress.net and have a developer help ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to short (truncate) long products title in WooCommerce category pages?’ is closed to new replies.