WooCommerce how do you change Cart to Basket?

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.

Recommended books for WordPress & WooCommerce


Search


Recent Posts



Popular Posts




You May Also Like…

Find similar blogs in these categories: wordpress
10 Comments
  1. Tommy

    This work perfectly thank you.

    Reply
  2. Mick

    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?

    Reply
    • admin

      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.

      Reply
      • Mick

        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);

        Reply
          • admin

            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

  3. Aidan

    Just implemented this, thank you

    Reply
  4. Anthony

    Thank you so much!!! The most helpful text changing snippet on the web!

    Reply
Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.