Nicola Mustone

Support Lead @ Automattic


Leadership, web, programming. Short essays and hands-on guides, focused on results, not hype.


How to Change the Add to Cart Text Everywhere in WooCommerce

4–7 minutes
a farmer standing by a fruit stand

WooCommerce provides immense flexibility for personalization. One common customization is how to change the Add to Cart text to make it resonate more with their brand or target audience.

If you’ve ever wondered how to modify this text everywhere in your store, you’re in the right place. A small change like this can improve the shopping experience for the customer and increase sales.

Understanding the Importance of Customization

Before we delve into the “How” let’s discuss the “Why” you should have a custom Add to Cart button.

Customizing elements like the Call to Action text can seem trivial. However, in the realm of e-commerce, even such details can influence customer behavior.

Tailoring the WooCommerce Add to Cart text can align more closely with your brand voice and increase sales and user engagement. Similarly, adding buttons with a custom Add to Cart URL can do the same.

A screenshot of a single product page from elementalbeacon.com showing the product image on the left, and the product data on the right. The image showcases a custom Add to Cart button with the text Add to Bag of Holding.
I customized the Add to Cart button on this shop to read Add to Bag of Holding. This text is thematic for this D&D shop.

How to Change the Add to Cart Text

Before you make any code changes, have a backup of your site. This will help you restore things in case of unforeseen errors. I recommend using Jetpack Backup for real-time backups and one-click restores.

If you want to change the Add to Cart text in WooCommerce to anything else, the process is straightforward. Thanks to the flexible nature of WooCommerce and WordPress, a code snippet can achieve this.

Add these snippets to your functions.php file.

1. Add to Cart Text on the Single Product Pages

/**
 * @snippet       Change the Add to Cart Text on Single Product Page
 * @author        Nicola Mustone
 * @author_url    https://nicolamustone.blog/2023/10/30/how-change-add-to-cart-text-everywhere-woocommerce/
 * @tested-up-to  WooCommerce 10.3.X
 * @license       GPLv2
 */
add_filter( 'woocommerce_product_single_add_to_cart_text', function( $text, $product ) {
    return 'Add to Bag';
}, 10, 2 );

2. Add to Cart Text by Category on the Single Product Page

/**
 * @snippet       Change the Add to Cart Text on Single Product Page by Category
 * @author        Nicola Mustone
 * @author_url    https://nicolamustone.blog/2023/10/30/how-change-add-to-cart-text-everywhere-woocommerce/
 * @tested-up-to  WooCommerce 10.3.X
 * @license       GPLv2
 */
add_filter( 'woocommerce_product_single_add_to_cart_text', function( $text, $product ) {
    $fallback = 'Add to Bag';

    $map = [
        'posters'   => 'Custom Text for Posters Category',
        'paintings' => 'Custom Text for Paintings Category',
        'pictures'  => 'Custom Text for Pictures and Frames Categories',
        'frames'    => 'Custom Text for Pictures and Frames Categories',
    ];

    $terms = get_the_terms( $product->get_id(), 'product_cat' );
    if ( empty( $terms ) || is_wp_error( $terms ) ) {
        return $fallback;
    }

    foreach ( $terms as $term ) {
        if ( isset( $map[ $term->slug ] ) ) {
            return $map[ $term->slug ];
        }
    }

    return $fallback;
}, 10, 2 );

3. Add to Cart Text on Shop Pages

/**
 * @snippet       Change the Add to Cart Text on Shop Pages
 * @author        Nicola Mustone
 * @author_url    https://nicolamustone.blog/2023/10/30/how-change-add-to-cart-text-everywhere-woocommerce/
 * @tested-up-to  WooCommerce 10.3.X
 * @license       GPLv2
 */
add_filter( 'woocommerce_product_add_to_cart_text', function( $text, $product ) {
    return 'Add to Bag';
}, 10, 2 );

4. View Cart Text in the Added to Cart Notices

/**
 * @snippet       Change the View Cart text
 * @author        Nicola Mustone
 * @author_url    https://nicolamustone.blog/2023/10/30/how-change-add-to-cart-text-everywhere-woocommerce/
 * @tested-up-to  WooCommerce 10.3.X
 * @license       GPLv2
 */
add_filter( 'wc_add_to_cart_message_html', function( $message ) {
    // Replace whole word "cart" only (case-insensitive)
    return preg_replace( '/\bcart\b/i', 'Bag', $message );
}, 10 );

The Magic Behind the Snippet

At a glance, the snippets above might seem complex, especially if you’re new to WooCommerce customizations. However, they are simpler than they look.

The filters woocommerce_product_single_add_to_cart_text and woocommerce_product_add_to_cart_text target the button text for single product pages and product archives, respectively. The filter wc_add_to_cart_message_html targets instead the “added to cart” message and the “view cart” link that appears after adding a product to the cart.

By applying the custom function, you override the default text with your preferred choice.

Add to Cart Text Blanket Solution

In some cases, the snippets above might just not be enough. This happens when plugins or themes do not use the WooCommerce filters in their templates. One example is with the theme Shoptimizer and the plugin CommerceGuru.

If that is the case, then a blanket solution by text-domain will cover those cases:

/**
 * @snippet       Change the Add to Cart Text Everywhere by Textdomain
 * @author        Nicola Mustone
 * @author_url    https://nicolamustone.blog/2023/10/30/how-change-add-to-cart-text-everywhere-woocommerce/
 * @tested-up-to  WooCommerce 10.3.X
 * @license       GPLv2
 */
add_filter( 'gettext_woocommerce', 'nm_change_cart_text', 20, 3 );
function nm_change_cart_text( $translated_text, $text, $domain ) {
	$map = [
        'Add to cart'   => 'Add to Bag',
        'View cart'     => 'View Bag',
        'Added to cart' => 'Added to Bag',
        'Cart'          => 'Bag',
    ];
    return $map[ $translated ] ?? $translated;
}

// Example for the theme Shoptimizer
add_filter( 'gettext_shoptimizer', 'nm_change_cart_text', 20, 3 );

// Example for the plugin CommerceKit
add_filter( 'gettext_commercegurus-commercekit', 'nm_change_cart_text', 20, 3 );

In the example above, gettext_woocommerce will target any text with the woocommerce text domain. gettext_shoptimizer will target any text with the domain shoptimizer. The last filter, gettext_commercegurus-commercekit, targets CommerceKit.

Before using it, adjust the filter names using the text domain of the plugin or theme you want to target.

Finding the Text Domain

To find the text domain you need to use do this:

  • Themes: download the theme and open its folder. In the main folder, you will find a file named style.css. Open it with your favorite text editor such as Notepad (not Microsft Word or similar).

    At the very beginning of the file, you will find a block starting with /*. Find the line that reads Text Domain: something. The value after Text Domain will be the text domain you’re looking for.
  • Plugins: download the plugin and open its folder. In the main folder, you should find a file with a name similar to the folder name and the extension .php. Open it with your favorite text editor such as Notepad (not Microsft Word or similar).

    At the very beginning of the file, you will find a block starting with /*. Find the line that reads Text Domain: something. The value after Text Domain will be the text domain you’re looking for.
    • If the plugin does not have a file name like its folder, open the PHP files individually until you find it. The file must be in the main folder, not its subfolders.

Note that this method can consume lots of resources on your server. I do not recommend it unless it’s the only solution that would work for you.

The image shows the header block of the file style.css for the theme Shoptimizer, highlighting the text domain line.
The Text Domain of the theme Shoptimizer in the shoptimizer/style.css file.

Wrapping Up

Tweaking the details of your WooCommerce store can offer a more personalized experience for your customers. It’s all part of the broader picture of WooCommerce customization. These changes make your online store truly your own.

Have you tried other customizations on your WooCommerce store? Share your experiences in the comments below, and let’s learn together!

If you found this guide helpful, read my article about changing the Continue Shopping redirect URL.

Cite This Essay

Use this ready-formatted reference in your work or research notes.


Leave a Comment

Discover more from Nicola Mustone

Subscribe now to keep reading and get access to the full archive.

Continue reading