Adjust ‘Read More’ button text for sold-out products

This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our Support Policy.

This snippet changes the ‘Read More’ button on the product catalog page for sold out products, to indicate that they are sold out. It does not affect variable products as separate variations may have different stock availability levels.

Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

/**
* Change add to cart button text to "Sold Out" for out-of-stock products
* (except variable products, which keep their normal text like "Select options").
*/
function custom_sold_out_button_text( $text, $product ) {
if ( ! $product instanceof WC_Product ) {
return $text;
}
$type = $product->get_type();
// Keep default text for variable products and variations
if ( $type === 'variable' || $type === 'variation' ) {
return $text;
}
// For all other product types, if it's out of stock, label it as "Sold Out"
if ( ! $product->is_in_stock() ) {
return __( 'Sold Out', 'woocommerce' );
}
// Otherwise, keep the default text
return $text;
}
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_sold_out_button_text', 10, 2 );