How to change add to cart button text woocommerce

Welcome to my blog friends, today I will give you the tips to change add to cart button text woo commerce. When I did an eCommerce project on WordPress using woo commerce plugin, I need to change “Add to Card” text on the product page to “Buy Now”. For solving the issue I changed the woo commerce core file. But this is not the proper solution. Whenever I update woo commerce plugin my code will be lost. After searching for sometimes I find this filter hook in woo commerce “woocommerce_product_add_to_cart_text”. Using this hook I can do my task easily. So using this blog I will share my code with you. If you want to change your “add to cart” button text to any other text you can use the below code.

Before using the code please read the instruction properly:




Process 1:Change the add to cart text on single product pages
Add the below code to your theme functions.php file
WooCommerce <2.1

add_filter( ‘add_to_cart_text’, ‘my_custom_cart_button_text’ );    // < 2.1
function my_custom_cart_button_text() {
        return __( ‘Your Custom 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 __( 'Your Custom Button Text', 'woocommerce' );
}

Change the add to cart text on product listing(product archives) page
Add the below code to your theme functions.php file
WooCommerce <2.1

add_filter( ‘add_to_cart_text’, ‘my_archive_custom_cart_button_text’ );    // < 2.1
function my_archive_custom_cart_button_text() {
        return __( ‘Your Custom Button Text’, ‘woocommerce’ );
}

WooCommerce 2.1+

add_filter( 'woocommerce_product_add_to_cart_text', 'my_archive_custom_cart_button_text' );    // 2.1 +
function my_archive_custom_cart_button_text() { 
        return __( 'Your Custom Button Text', 'woocommerce' );
}

Change the add to cart text on product archives by various product types
Add the below code to your theme functions.php file

add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );

function custom_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' );
	}
	
}

Now you know how to change add to cart button text woo commerce. I hope the above codes will help you to change woo commerce add to cart text to your custom text. If you face any problems please comment below.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •