Skip to main content
Login Join
Snippet · PHP

Change WooCommerce Product Button Text Based on Stock Status

Shared by Amit Dholiya · September 2, 2026 · @woocommerce_product_add_to_cart_text

8 views
Back to Snippets

You can customize the Add to Cart button text depending on whether a product is in stock. This is useful for making the shopping experience clearer for customers.

Steps

  1. Open your theme’s functions.php file.
  2. Add the code below.
  3. Save the file.
  4. Open your Shop or Product page.

Done — the button text will change based on the product’s stock status.

function custom_add_to_cart_button_text( $text, $product ) {

    if ( ! $product->is_in_stock() ) {
        return 'Notify Me';
    }

    return 'Buy Now';
}

add_filter(
    'woocommerce_product_add_to_cart_text',
    'custom_add_to_cart_button_text',
    10,
    2
);
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments