Actually my full code will include checking statement to replace the customized text only to product items as below:
function custom_search_read_more_text( $more ) {
if ( is_search() ) {
global $post;
if ( 'product' === get_post_type( $post ) ) {
return ' <a class="more-link" href="' . get_permalink( $post ) . '">View Product</a>';
} else {
return ' <a class="more-link" href="' . get_permalink( $post ) . '">Read More</a>';
}
}
return $more;
}
add_filter( 'excerpt_more', 'custom_search_read_more_text' );
But as I tried just plain returning without the if, none of the above ever worked. So I simplified it here to make they read easier.