There are times when you want to change a few words in Woocommerce to match the content on your website. For example, change the text of the purchase button to your liking or to match the type of product you sell. You can absolutely use a plugin to do this. However, if you only want to change a few words, you can use code to change it.
The code below will help you for WooCommerce in a completely easy way. For example, your product page has a Discount button! and Purchases , and you want to change them Special Price and Buy Now

You can add the following PHP code at the end of your child theme’s functions.php file (after the ” <?php ” character and before the ” ?> ” character if applicable). You should edit in the child theme, if the interface you use does not have a child theme, you can review the article: Instructions for creating a Child theme .
add_filter( 'gettext', 'hocwordpress_translate_woocommerce_strings', 999 );
function hocwordpress_translate_woocommerce_strings( $translated ) {
$translated = str_ireplace( 'Mua hàng', 'Mua ngay lập tức', $translated );
$translated = str_ireplace( 'Giảm giá', 'Giá ưu đãi', $translated );
return $translated;
}
<div>
<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span>
</div>
You can use the above structure to change other letters if you want. By adding the following line and editing the characters again as you like:
$translated = str_ireplace( 'Giảm giá', 'Giá ưu đãi', $translated );<div><span>1</span></div>
Now go back to the product page and reload the page to see the results.

