Custom Stock Availability Messages
Replaces the standard "Out of stock" and "Available on backorder" labels on product pages with your own wording.
Opens WPIDE on
Code
add_filter( 'woocommerce_get_availability_text', function ( $text, $product ) {
// Your wording for each stock status. Empty keeps the default.
$messages = array(
'outofstock' => 'Sold out, back soon',
'onbackorder' => 'Ships in 2-3 weeks',
);
if ( ! $product instanceof WC_Product ) {
return $text;
}
$status = $product->get_stock_status();
return ! empty( $messages[ $status ] ) ? $messages[ $status ] : $text;
}, 10, 2 );
Notes
Leave a message empty to keep the WooCommerce default for that status.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.