How to use filter to replace text instead of appending?

[ad_1]

Hello!

I got the code below from ChatGPT but couldn’t debug it. It almost works except the original text I want to replace is still present but to the right.

Right now it says: “1 customer review” if it’s one or “\[number\_of\_reviews\] customer review**s**” if it’s more than one. I want it to say

‘Ver 1 avaliação” and “Ver \[number\_of\_reviews\] avaliações”, respectively:

add_filter( ‘woocommerce_product_review_count’, ‘custom_product_review_count’, 10, 2 );
function custom_product_review_count( $count, $product ) {
return sprintf( ‘Ver %d avaliaç%s’, $count, ( $count > 1 ? ‘ões’ : ‘ão’ ) );
}

This code also had the same problem:

add_filter( ‘woocommerce_product_review_count’, ‘custom_product_review_count’, 10, 2 );
function custom_product_review_count( $count, $product ) {
return ‘Ver ‘ . $count . ‘ avaliaç’ . ( $count > 1 ? ‘ões’ : ‘ão’ );
}

Thanks a lot!

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer