Change WooCommerce Out of Stock Text to Sold Out

WooCommerce shows “Out of stock” on product pages and a “Read more” button in the shop when a product cannot be bought. This snippet changes the WooCommerce Out of stock text to “Sold out”, which customers read faster, and uses the same words on the shop button.

Products that can still be ordered, including products on backorder, keep WooCommerce’s own texts.

The snippet

<?php
/**
 * Show "Sold out" instead of WooCommerce's "Out of stock" text and button label.
 */

// ===== Config =====
function dpc_sold_out_text() {
	return __( 'Sold out', 'dpc' );
}
// ===== End of config =====

// The stock notice on the product page, also for single variations.
add_filter( 'woocommerce_get_availability_text', 'dpc_sold_out_availability_text', 10, 2 );

function dpc_sold_out_availability_text( $text, $product = null ) {
	if ( $product instanceof WC_Product && ! $product->is_in_stock() ) {
		return dpc_sold_out_text();
	}

	return $text;
}

// The "Read more" button of out of stock products in the shop, categories and product blocks.
add_filter( 'woocommerce_product_add_to_cart_text', 'dpc_sold_out_button_text', 10, 2 );

function dpc_sold_out_button_text( $text, $product = null ) {
	if ( $product instanceof WC_Product && ! $product->is_in_stock() && ! $product->is_type( 'external' ) ) {
		return dpc_sold_out_text();
	}

	return $text;
}

How it works

  • woocommerce_get_availability_text sets the stock notice under the price on the product page. For variable products it is also used for each variation, so a sold out size shows “Sold out” when it is selected.
  • woocommerce_product_add_to_cart_text sets the button text in the shop, on category pages, in related products and in product blocks and shortcodes. Out of stock products show a link to the product there, now labelled “Sold out”.
  • Both filters use the product WooCommerce passes in and is_in_stock(), so it works outside the main loop and treats backorders as available.
  • External/affiliate products keep their own button text.

The older version of this post only changed the add to cart button on the product page, which WooCommerce does not show for out of stock simple products, read the global $product, labelled backorders as sold out and forced “Add to cart” on every other product.

Add it with Scripts Organizer

In Scripts Organizer go to Code Blocks → Add New and give the block a name. Set Trigger location to Everywhere, tick PHP under Script location, paste the code into the PHP editor and publish. Leave Action/Hook empty. The code only adds filters, so it can load before WooCommerce. Product lists are also rendered in REST requests and blocks, which Everywhere covers.

The same code also works unchanged in a small plugin or an mu-plugin.

Customise it

Gotchas

  • The shop button still links to the product page; it only says “Sold out” instead of “Read more”.
  • If Hide out of stock items from the catalog is on under WooCommerce → Settings → Products → Inventory, sold out products are not listed, so only the product page text changes.
  • Some themes and page builders print their own “Sold out” badge on product images; that badge comes from the theme, not from this snippet.

In the Scripts Organizer library Import it with one click from Scripts Organizer.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You’ll also get DPlugins product updates. No spam, and you can unsubscribe anytime.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You'll also get DPlugins product updates. No spam, and you can unsubscribe anytime.