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
- Open your theme’s
functions.phpfile. - Add the code below.
- Save the file.
- 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
);