WooCommerce is great but there doesn’t seem to be a built in easy way to change the American term ‘Shopping Cart’ to ‘Shopping Basket’. If you are running a British or European based business changing this phrase is essential if you want your store to look professional.
I have developed a simple solution. All you need to do is paste the following function into your themes functions.php.
add_filter('gettext', function ($translated_text, $text, $domain) { if ($domain == 'woocommerce') { switch ($translated_text) { case 'Cart totals': $translated_text = __('Order summary', 'woocommerce'); break; case 'Update cart': $translated_text = __('Update basket', 'woocommerce'); break; case 'Add to cart': $translated_text = __('Add to basket', 'woocommerce'); break; case 'View cart': $translated_text = __('View basket', 'woocommerce'); break; } } return $translated_text; }, 20, 3);
This code processes all the output from your WordPress WooCommerce store and dynamically replaces Cart with Basket.
If you have any questions, or if you spot somewhere in Woocommerce that I’ve missed do please leave a comment below.
This work perfectly thank you.
Thanks so much for this! A couple of places still showing cart:
“Your cart is currently empty.”
“… has been added to your cart.”
I tried fixing these by adding amended snippets of your code, but it didn’t work. Any thoughts?
Hi Mick,
The first thing I would check is that you have definitely added this to the functions.php for your active theme. After that double check that you have pasted all the code in correctly including the add_filter(‘gettext’, on the first line. If it still doesn’t work may be you could upload your functions.php and I’ll take a look for you.
Thanks for your reply. I’m using Code Snippets plugin rather than adding directly to functions.php, which like I said works for the above code perfectly. Here’s the snippet with the extra 2 bits of text I’ve added, which don’t do anything:
add_filter(‘gettext’,
function ($translated_text, $text, $domain) {
if ($domain == ‘woocommerce’) {
switch ($translated_text) {
case ‘Cart totals’:
$translated_text = __(‘Order summary’, ‘woocommerce’);
break;
case ‘Update cart’:
$translated_text = __(‘Update basket’, ‘woocommerce’);
break;
case ‘Add to cart’:
$translated_text = __(‘Add to basket’, ‘woocommerce’);
break;
case ‘View cart’:
$translated_text = __(‘View basket’, ‘woocommerce’);
break;
case ‘has been added to your cart’:
$translated_text = __(‘has been added to your basket’, ‘woocommerce’);
break;
case ‘Your cart is currently empty’:
$translated_text = __(‘Your basket is currently empty’, ‘woocommerce’);
break;
}
}
return $translated_text;
},
20, 3);
Turns out I didn’t need any of the code! There’s a Woo translation file for English (GB). I just needed to switch language setting in the main WP settings, then update the language files (which includes Woo).
Here’s the link:
https://docs.woocommerce.com/document/woocommerce-localization/
Thank Mick,
I’m pleased that works for you. If you do need to use the ‘get text’ translate function in the future the reason it didn’t work is the string to be translated only ends with “added to cart”, eg “MacBook, has been added to cart”, so when it does the test it fails as the strings are not equal. I will post an updated version of the code when I get a chance which supports scanning for substrings and replacing these as well.
Linda
Just implemented this, thank you
Hiya,
Did you ever post the updated version of the code by chance?
Hi Jule,
Since I wrote the above code snippet, WooCommerce have added localisation support. Please see https://docs.woocommerce.com/document/woocommerce-localization/
Let me know how you get on with this.
Linda
Thank you so much!!! The most helpful text changing snippet on the web!