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
[php]
add_filter( ‘add_to_cart_text’, ‘my_archive_custom_cart_button_text’ );
function my_archive_custom_cart_button_text() {
return __( ‘My Button Text’, ‘woocommerce’ );
}
[/php]
WooCommerce 2.1+
[php]
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’ );
}
[/php]
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
[php]
add_filter( ‘add_to_cart_text’, ‘my_custom_cart_button_text’ ); // < 2.1
function my_custom_cart_button_text() {
return __( ‘My Button Text’, ‘woocommerce’ );
}
[/php]
WooCommerce 2.1+
[php]
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’ );
}
[/php]
Change the add to cart text on product archives by product types
Add the following to your functions.php file under your activated theme.
[php]
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’ );
}
}
[/php]
Views (238)

Chris Mok

Latest posts by Chris Mok (see all)
- WHM – Change account setup date manually - August 25, 2016
- Manually generate the notifications to who over disk quota - August 23, 2016
- Help Desk Management: What is Level 1, Level 2, and Level 3 Help Desk support? - July 27, 2016
- Find and delete files greater than a given size from the Linux command line - April 18, 2016
- How to change WordPress default email’s From name and address - April 15, 2016