Change ‘Read More’ button text to ‘Sold Out’ for out of stock 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 text on standard add to cart buttons, such as on the shop / product catalog page for sold out products, to indicate that they are sold out without needing to click through. It does not affect variable products as separate variations may have different stock availability levels.

Note: If you do not see any out of stock products on your shop’s catalog, ensure your Hide out of stock items from the catalog ticked under your store’s Product Inventory settings.

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 );
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.