Woocommerce is one of the most used plugins for the e-commerce websites and sometimes we have to change the “Add to Cart” button in just to make unique from the other websites.In changing the “Add to Cart” button label is very simple by using two filters “woocommerce_product_single_add_to_cart_text” and “woocommerce_product_add_to_cart_text”“woocommerce_product_single_add_to_cart_text” filer is used to change the “Add to Cart” label on product single page, and “woocommerce_product_add_to_cart_text” is use on archives pages.Copy and paste this code in your functions.php file.
// Change "Add to Cart" label on Archive page according to the product type
add_filter( 'woocommerce_product_add_to_cart_text' , 'my_custom_product_add_to_cart_text' );
function my_custom_product_add_to_cart_text() {
global $product;
// get the product type using global $product
$product_type = $product->product_type;
// Checked the current product type and change the "Add to Cart" label
switch ( $product_type ) {
case 'simple':
return __( 'Buy Me', 'my-plugin-slug' );
break;
case 'variable':
return __( 'Select One of Us', 'my-plugin-slug' );
break;
case 'external':
return __( 'Visit Me', 'my-plugin-slug' );
break;
case 'grouped':
return __( 'Pick Us', 'my-plugin-slug' );
break;
default:
return __( 'Add to Cart', 'my-plugin-slug' );
}
}
// Change 'add to cart' into 'Buy me'
add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_custom_add_to_cart_text' );
function my_custom_add_to_cart_text() {
return __( 'Buy Me', 'my-plugin-slug' );
}