WooCommerce - How To Change On Stock Text To Custom One

Mega Monsoon Days Sale

Limited-time deal: Up to 70% off Hurry before it ends!
Save Now

Days

Hrs

Min

Sec

Product successfully added to your shopping cart.

WooCommerce – How to Change Default “On Stock” Text to Custom One

Table of Contents

Open the functions.php file located under the “wp-content/themes/theme_name” folder.

Add the following code to the very end of the file:

add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
   // Change In Stock Text
   if ( $_product->is_in_stock() ) {
     $availability['availability'] = __('Available!', 'woocommerce');
   }
   // Change Out of Stock Text
   if ( ! $_product->is_in_stock() ) {
     $availability['availability'] = __('Sold Out', 'woocommerce');
   }
   return $availability;
}