• Resolved mylan.dros

    (@laurael)


    Hi!

    On archive page, I have a list of products with the title, the short description and the price. I’d like to add a limit to the description, for example 30 words.

    Can you help me do it?

    I tried to do that but it doesn’t seem to work as expected.

    add_filter('woocommerce_short_description','limit_short_descr');
    
    function limit_short_descr($description){
    	return ($description > 30) ? substr($description, 0 , 30) : $description;
    }

    Thanks for your help, I have a nice day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @laurael ,

    The approach you have taken here seems to be the right one.

    The only issue that I can see is in the condition. In PHP we need to use the function strlen() to be able to check the length of the string. So, this version of the code should work as per your expectation –

    add_filter('woocommerce_short_description','limit_short_descr');
    
    function limit_short_descr($description){
    	return (strlen($description) > 30) ? substr($description, 0 , 30) : $description;
    }

    I hope this helps.

    Thank you ??

    Thread Starter mylan.dros

    (@laurael)

    Hi!

    It does help! Thank you ?? Have a nice day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limit short description on archive page’ is closed to new replies.