Menu Close

WooCommerce: Change “Buy Product” Label for External Products

default

By default, WooCommerce displays a “Buy Product” button label for external products. This button redirects to the external URL that is entered via the single product settings.

As usual, this “Buy Product” label may not suit all businesses, and therefore WooCommerce gives you the option to rename such buttons via the single product edit page settings. This is great, but at the same time you don’t want to manually edit hundreds of products when you can use a few lines of PHP, right?

So, here’s a super quick fix to override the “Buy Product” external add to cart button label to whatever you wish, without ever touching the manual settings. Enjoy!

With a few lines of code I was able to change the default external product add to cart button label “Buy Product” into “Buy Now ->“. Avoiding manual work via the WooCommerce product settings is always a great idea!

PHP Snippet: Override the “Buy Product” External Product Add to Cart Label @ WooCommerce Single Product & Shop Pages

/**
 * @snippet       Edit "Buy Product" External Add to Cart Button Label
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_product_single_add_to_cart_text', 'bbloomer_override_external_button_label', 9999, 2 );
add_filter( 'woocommerce_product_add_to_cart_text', 'bbloomer_override_external_button_label', 9999, 2 );

function bbloomer_override_external_button_label( $text, $product ) {
	if ( $product->is_type( 'external' ) ) $text = 'Buy Now →';
	return $text;
}
View Source
Posted in WooCommerce Tips