WooCommerce has provided many hooks and actions so anyone can customize it accordingly. To change Add to Cart text we are going to use 2 hooks and it depends on your requirement whether you want to change the text on the product archive page or to the single product page.
Make sure that you have access to your functions.php
file and paste the below code (whichever you required) at the end of your functions.php
file.
No worries if you don’t have access to your functions.php
file. You could use the WPCode plugin.
- Change “Add to Cart” text on the entire site
- Change “Add to Cart” text on single product only
- Change “Add to Cart” text on a particular product
- Change “Add to Cart” text on specific product type
Change “Add to Cart” text on the entire site
You can use the following snippet if you like to change “Add to Cart” text to product archive page or single product page.
add_filter( 'woocommerce_product_add_to_cart_text', 'wrg_add_to_cart_text' );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wrg_add_to_cart_text' );
function wrg_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
Change “Add to Cart” text on single product only
If you like to change “Add to Cart” text on single product page then you can use the following code.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wrg_add_to_cart_text' );
function wrg_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
Change “Add to Cart” text on a particular product
If you wish to change “Add to Cart” text on a particular product page, then you can use the following snippet.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wrg_add_to_cart_text', 10, 2 );
function wrg_add_to_cart_text( $add_to_cart_text, $product ) {
// Check particular product
if (in_array($product->id, ['YOUR_PRODUCT_ID'])) {
return __( 'Buy Now', 'woocommerce' );
}
return $add_to_cart_text;
}
Change “Add to Cart” text on specific product type
You can use the following snippet if you wish to change “Add to Cart” text based on specific product type like simple, grouped, variable or external.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wrg_add_to_cart_text', 10, 2 );
function wrg_add_to_cart_text( $add_to_cart_text, $product ) {
// 'simple', 'grouped', 'variable', 'external'
if ( $product->is_type('simple') ) {
return __( 'Buy Now', 'woocommerce' );
}
return $add_to_cart_text;
}
We believe this article will help you to change “Add to cart” text in WooCommerce. And if you enjoyed this article, then please follow us for more interested and helpful tutorials. You can follow us on Facebook and Twitter.
Don’t worry, If you have doubts or not able to achieve the desired result in WordPress. We are open to providing you the WordPress support.