I am trying to change some text on my WooCommerce-based WP Website.
Essentially, through a filter using the str_replace I’m trying to change the text ‘%s reviews for %s’ to be something else.
This text is included in the single-product-reviews.php file.
See below:
<h2><?php
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ($count = $product->get_review_count() ) )
printf( _n( '%s review for %s', '%s reviews for %s', $count, 'woocommerce' ), $count, get_the_title() );
else
_e( 'Reviews', 'woocommerce' );
?></h2>
In order to do this I’m trying to use the following, but it doesn’t seem to work. I’m not sure what string I should be targetting.
function lnz_replace_content()
{
echo str_replace("%s reviews for %s","%s comments about %s", $product);
}
add_filter('init','lnz_replace_content');'
I’ve had a go with gettext too but that doesn’t seem to work either in this case.
OP Update
I’ve had a go at using gettext, but it doesn’t seem to work in this case.
As previously mentioned, I’m targeting the following code (in single-product-review.php)
<h2><?php
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_review_count() ) )
printf( _n( '%s review for %s', '%s reviews for %s', $count, 'woocommerce' ), $count, get_the_title() );
else
_e( 'Reviews', 'woocommerce' );
?></h2>
If I use ‘gettext’ to replace ‘Reviews’ it works fine. If I try and get it to replace ‘% review for %s’ it doesn’t work.
Any ideas why.
you can do this with 2 ways:
1) change in language file:
2) chang code:
to
You can use the template overrides to override
single-product-reviews.php
by copying it into your theme’swoocommerce
folder.or you can filter
gettext
from your theme’sfunctions.php