I need to change the default “Add To Cart” button text to ”Buy now“. I solved it by adding such a function to the function.php file of the child theme:
add_filter('woocommerce_product_add_to_cart_text', 'replace_cart_text');
add_filter('woocommerce_product_single_add_to_cart_text', 'replace_cart_text');
function replace_cart_text()
{
return 'Buy now';
}
The problem is that I use different languages on the site. How to modify function to display different text on the buttons for each language? My translation plugin is Polylang.
CodePudding user response:
You can try with the plugin references in the below link for a better translation for woocommerce.
https://www.cloudways.com/blog/woocommerce-multilingual/
CodePudding user response:
I solved this problem by adding condition to the function:
add_filter('woocommerce_product_add_to_cart_text', 'replace_cart_text');
add_filter('woocommerce_product_single_add_to_cart_text', 'replace_cart_text');
function replace_cart_text() {
if (get_locale() == 'de_DE') {
return 'Kaufen';
}
if (get_locale() == 'en_US') {
return 'Buy now';
}
}