Change the Add to Cart Button Text
Replaces "Add to cart" with "Buy now" on single product pages and on shop listings for simple, in-stock products.
Opens WPIDE on
Code
add_filter( 'woocommerce_product_single_add_to_cart_text', function () {
return 'Buy now';
} );
add_filter( 'woocommerce_product_add_to_cart_text', function ( $text, $product = null ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() ) {
return 'Buy now';
}
return $text;
}, 10, 2 );
Notes
Edit both "Buy now" strings.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.