I am using the below code that Automatically shortens WooCommerce product titles on the static home page main shop, category, and tag pages. I want to do also that for related products. what conditional tag should i add for related product here
This code automatically shortens WooCommerce product titles on the static home page main shop, category, and tag pages to a set number of characters
function short_woocommerce_product_titles_chars( $title, $id ) {
if ( ( is_front_page() || is_shop() || is_product_tag() || is_product_category() ) && get_post_type( $id ) === 'product' ) {
// Kicks in if the product title is longer than 60 characters
if ( strlen( $title ) > 60) {
// Shortens it to 60 characters and adds ellipsis at the end
return substr( $title, 0, 60 ) . '...';
}
}
return $title;
}
add_filter( 'the_title', 'short_woocommerce_product_titles_chars', 10, 2 );
2
Answers
You can check this article. Hope it will be solve your issues.
https://designsmaz.com/how-to-short-woocommerce-products-title/#comment-76957
The following will extend your current code to related product too:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.