How to replace comment author name with Asterix on Woocommerce Wordpress

You can replace comment author name with Asterix on Woocommerce wordpress product page by changing the following file under plugin file editor in wordpress backend:

woocommerce/templates/single-product/review-meta.php

Make amendments to line 34






Under the class "meta" div, you can include the following lines:

<?php

$comment = get_comment( $comment->comment_ID );

$comment_author = get_comment_author($comment);

?>

<strong class="woocommerce-review__author"><?php echo transformString($comment_author); ?> </strong>

Do note that the output makes use of a custom function to transform the comment author's name into asterix in your required format. 

You can add this function to the bottom of the same file so you will not get any errors:
function transformString($inputString) {
return substr($inputString, 0, 2) . str_repeat('*', strlen($inputString) - 3) . substr($inputString, -1);

Do note that editing this file directly is not recommended as an update for the woocommerce plugin will revert your changes back to normal. You can duplicate this file to your child theme following instructions on line 5 of the same file.

For full instructions on building your own child theme, you can always refer to the wordpress docs.

Post a Comment

0 Comments