This tutorial will show 2 methods how to change ‘In Stock’ / ‘Out of Stock’ text displayed on a product page in WooCommerce single…


WooCommerce: How to change In Stock or Out of Stock text on a product page

This tutorial will show 2 methods how to change ‘In Stock’ / ‘Out of Stock’ text displayed on a product page in WooCommerce single product page.

Method #1:

Step 1). Log into WordPress admin panel, navigate to Appearance-> Editor tab and open functions.php to edit:

Step 2). Put below code to the bottom of the functions.php 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;
}

Save the file above and done. You’ve told WooCommerce to get custom status for stock display at single product pages.

Method #2:

If the above method does not work due to the possibility of theme custom default woo-commerce status.

Copy and paste this code to the bottom of your themes functions.php file:

add_filter( 'gettext', 'customizing_product_variation_message', 10, 3 );
function customizing_product_variation_message( $translated_text, $untranslated_text, $domain )
{
if ($untranslated_text == 'Out of Stock') {
$translated_text = __( 'Sold Out', $domain );
}
return $translated_text;
}
  • $untranslated_text is the current text status.
  • $translated_text is your new chosen text status.

We hope this article helps you change the stock text on your Woocommerce product page. For any query regarding this topic, please don’t forget to leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *