WooCommerce Add to Cart Text Generator

Change the WooCommerce add to cart button text on the product page, in the shop loop, or only for one product type or category.

Live output

Enable JavaScript to customise; default output below.

Live preview add-to-cart-text.php
<?php
/**
 * Add to cart button wording.
 */

/**
 * The button on the product page.
 *
 * @param string     $text    Current label.
 * @param WC_Product $product The product being shown.
 * @return string
 */
function my_store_single_add_to_cart_text( $text, $product ) {
	if ( ! $product->is_in_stock() ) {
		return $text;
	}

	return __( 'Buy now', 'my-store' );
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_store_single_add_to_cart_text', 10, 2 );

/**
 * The button in the shop and category listings.
 *
 * @param string     $text    Current label.
 * @param WC_Product $product The product being listed.
 * @return string
 */
function my_store_loop_add_to_cart_text( $text, $product ) {
	// A variable product links to the page instead of adding to the cart, so
	// leave its wording alone unless you mean to promise something it cannot do.
	if ( ! $product->is_purchasable() || ! $product->is_in_stock() ) {
		return $text;
	}

	return __( 'Add to basket', 'my-store' );
}
add_filter( 'woocommerce_product_add_to_cart_text', 'my_store_loop_add_to_cart_text', 10, 2 );

Output is valid and updates as you type.

Change what the add to cart button says, on the product page, in the listings, or only for one product type or category. The generator writes both filters, because the two buttons are not the same one.

How to use

  1. Set the product page wording first. That is the button most people mean when they say “add to cart”.
  2. Leave the listing filter on. The shop grid uses a separate filter, which is why one button changes and the other does not.
  3. Narrow the scope when the wording only fits part of the catalogue. “Download now” on a physical product is worse than the default.
  4. Be careful in the listing: a variable product’s button links to the product page instead of adding anything, so the generated code leaves those alone.
  5. Put the snippet in a site specific plugin so the wording survives a theme change.

Example

Different wording for one category only, on both buttons:

function acme_single_add_to_cart_text( $text, $product ) {
	if ( ! has_term( 'gift-cards', 'product_cat', $product->get_id() ) ) {
		return $text;
	}

	if ( ! $product->is_in_stock() ) {
		return $text;
	}

	return __( 'Send this gift', 'acme' );
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'acme_single_add_to_cart_text', 10, 2 );

Returning $text rather than your own string in every case you do not handle is what keeps the rest of the store untouched.

Pitfalls

  • The product page and the listing use different filters. Changing one and wondering why the other is unchanged is the most common report.
  • Both filters pass the product as the second argument, but only if you register with 10, 2. Leave the argument count off and $product is null.
  • A variable product in the listing shows a link, not an add to cart button. Labelling it “Add to cart” promises something the button does not do.
  • Out of stock products keep their own label. Overriding it without checking stock tells people to buy something they cannot.
  • Translating your new string with a text domain your snippet does not load leaves it untranslated. Use the plugin’s own domain.
  • External products use the button text stored on the product. A filter here competes with what the merchant typed in the product editor.
  • Wording changes affect analytics that key on button text. Check any event tracking before shipping.
  • Caching plugins serve the old label from HTML cache. Clear it after deploying.

Compatibility

woocommerce_product_single_add_to_cart_text and woocommerce_product_add_to_cart_text have both passed the product object since WooCommerce 3.0, and still apply in WooCommerce 8 and 9 with classic product templates. Product blocks in a block theme render the same filters through the add to cart block. The generated code targets PHP 7.0 and up, and the tool runs entirely in your browser.

Frequently asked questions

Why did only one button change?
There are two filters. The product page and the shop loop each have their own, and the generated snippet covers both.
How do I change it for one product only?
Check the ID inside the filter: if ( 123 !== $product->get_id() ) { return $text; }. Category or type scoping is usually easier to maintain.
Does this work with the product blocks?
Yes for the add to cart block, which runs the same filters. Fully custom block markup may not.
Can I change the text on the cart or checkout button?
Those are different strings again: the cart’s proceed button and the place order button each have their own filter.
Why is my text not translated?
The text domain in the snippet has to be one that is actually loaded. Using a theme’s domain from a plugin file loads nothing.

From the people who built this tool

WP Adminify

The WordPress admin, rebuilt: a dashboard worth looking at, menu and column control, a real file manager and the login page your client sees.

See WP Adminify Free version on WordPress.org

Weekly drops

New tools, when there are new tools

One email when something worth using ships. No schedule to fill, so no filler.

Your address goes nowhere else, and one click unsubscribes.