WooCommerce – How to change “Add to cart” button text, Tips & Tricks

I’d like to share how to change “Add to cart” text of the WooCommerce.

Change the add to cart text on product archives

Add the following to your functions.php file under your activated theme.

WooCommerce <2.1

add_filter( 'add_to_cart_text', 'my_archive_custom_cart_button_text' );
function my_archive_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

WooCommerce 2.1+

add_filter( 'woocommerce_product_add_to_cart_text', 'my_archive_custom_cart_button_text' );
function my_archive_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

Change the add to cart text on single product pages

Add the following to your functions.php file under your activated theme.

WooCommerce <2.1

add_filter( 'add_to_cart_text', 'my_custom_cart_button_text' );    // < 2.1
function my_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

WooCommerce 2.1+

add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_custom_cart_button_text' );    // 2.1 +
function my_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

Change the add to cart text on product archives by product types

Add the following to your functions.php file under your activated theme.

add_filter( 'woocommerce_product_add_to_cart_text' , 'my_woocommerce_product_add_to_cart_text' );
function my_woocommerce_product_add_to_cart_text() {
	global $product;
	
	$product_type = $product->product_type;
	
	switch ( $product_type ) {
		case 'external':
			return __( 'Buy product', 'woocommerce' );
		break;
		case 'grouped':
			return __( 'View products', 'woocommerce' );
		break;
		case 'simple':
			return __( 'Add to cart', 'woocommerce' );
		break;
		case 'variable':
			return __( 'Select options', 'woocommerce' );
		break;
		default:
			return __( 'Read more', 'woocommerce' );
	}
	
}

Views (130)

Share on Facebook0Share on Google+0Share on LinkedIn0Tweet about this on TwitterEmail this to someonePrint this page
[Total: 1    Average: 5/5]

Leave a Reply

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

1 − 1 =