Changing WooCommerce 'Cart' text sitewide

05 August, 2014 by Tom Elliott

There are a number of ways you can change the text of the standard ‘Add to cart’ buttons in WooCommerce, along with other notifications such as ‘View cart’ and ‘Update cart’ that appear throughout the rest of your e-commerce site.

In the UK for example, we would usually refer to a ‘shopping cart’ as ‘shopping basket’ and so using the text ‘view basket’, ‘add to basket’ and so on for our WooCommerce buttons would be expected.

Depending what you want the ‘add to cart’ text to become, or if you want to change this text and other labels and buttons sitewide, will determine which of the following options is most appropriate.

These solutions have been tested with the latest versions of WordPress (3.9.1) and WooCommerce (2.1.12) at the time of writing.

Option 1. Update language in wp-config

By far the easiest and quickest way to update the ‘add to cart’ text sitewide in WooCommerce is to localize WordPress by setting the WPLANG option in the wp-config.php file.

The default setting for ‘WPLANG’ can be found around line 72 in the wp-config.php file and is usually:

define ('WPLANG', '');

If you wanted to change the American ‘cart’ to English (British) ‘Basket’ for example, you would need to update this to:

define ('WPLANG', 'en_GB');

There are many other common languages supported with WooCommerce and some of the most popular include:

Changing the language this way will also update all other WooCommerce labels and buttons such as ‘Proceed to Checkout’, ‘Order Total’ and ‘Cart subtotal’.

Option 2 – Specify localisation

If your desired language is not supported in WooCommerce by changing WPLANG, or you want finer control over labels and buttons such as ‘add to cart’, then creating your own language files (.po or .pot) for translation may be the best option.

You can find out how to do this with the WooCommerce language translation tutorial.

Option 3 – Update WooCommerce hooks

If you want to do update a handful of labels or button text to non-standard translations, or you don’t want to change the translation of other labels and text elsewhere in the order process, then updating specific WooCommerce hooks might be the best option.

You will need to find the appropriate hook for the text you want to update and make sure to include the hook in your theme’s functions.php file rather than updating woocommerce core files.

For example, the below hooks will update the ‘add to cart’ text on single product and product listing pages.

add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' );   

function woo_custom_cart_button_text() {
        return __( 'Add to basket', 'woocommerce' );
}


4 Comments

  • Thijs says:

    Hi, excellent article!

    The above example works fine.

    However, when I try to change other button labels, I am completely lost in how to do it.

    To be more precise ….: I cannot figure out the exact name for the hook!

    For instance, in Woocommerce docs I find hooks like:
    woocommerce_add_to_cart_handler
    woocommerce_add_to_cart_message
    woocommerce_add_to_cart_product_id
    woocommerce_add_to_cart_validation

    But the one you use in the above example is not mentioned:
    add_to_cart_text

    It drives me mad, because these button labels can only be changed by redefining them in functions.php (localization keeps them unchanged).

    Thanks a lot for helping me out!
    Kind regards
    Thijs

  • andy allen says:

    Hi,
    I can’t see WPLANG in my wp-config.php file – I’m using WP 4.1.1, know where else it could be?
    Cheers,
    Andy

  • Dodi says:

    That is nice but how I can change the word from whole site, I try WPLANG but its not working. I try other method and its working, but its change the ADD TO CART not MY CART. So how to change from whole site.