← Back to notes
snippet 1 min read PHP 7.4+ WP 5.8+

Change WooCommerce Add to Cart Text Dynamically Based on Product Category or Price

Change the single-product Add to Cart button label according to product category, price, or both.

Updated Aug 27, 2026 #woocommerce #products #php #snippet

The default Add to cart label is not always the best call to action. A store can use a more specific label such as Choose options for a category, or Request this item for a high-priced product.

This example changes the label on single-product pages and leaves archive buttons unchanged. Add it to a child theme’s functions.php file or a code snippets plugin.

The snippet

functions.php
add_filter( 'woocommerce_product_single_add_to_cart_text', function( $text, $product ) {
if ( ! $product instanceof WC_Product ) {
return $text;
}
// Category slugs are used here, not category display names.
if ( has_term( 'subscriptions', 'product_cat', $product->get_id() ) ) {
return __( 'Start subscription', 'my-site' );
}
if ( $product->get_price() && (float) $product->get_price() >= 1000 ) {
return __( 'Request this item', 'my-site' );
}
return $text;
}, 10, 2 );

For archive and shop-loop buttons, use the related filter as well:

functions.php
add_filter( 'woocommerce_product_add_to_cart_text', function( $text, $product ) {
if ( has_term( 'subscriptions', 'product_cat', $product->get_id() ) ) {
return __( 'Subscribe', 'my-site' );
}
return $text;
}, 10, 2 );

Variable and sale products

get_price() returns the active price WooCommerce is using, which can be affected by sale pricing and dynamic pricing filters. For variable products, the parent product may not have one final price before a variation is selected. If the price rule should apply to each variation, add the filter to the variation data or use the selected variation’s price in a small frontend script.

Use a category slug such as subscriptions, not a translated label such as Subscriptions. Keep labels short and action-oriented, and wrap them in translation functions so the button can be translated later.

The WooCommerce product button hook reference lists the related filters for single-product and loop buttons. If the store uses variations, also review how WooCommerce handles variable products before changing the call to action.