Menu Close

WooCommerce: Edit “# in stock” @ Single Product Page

default

I’ve seen many snippets that change the “In Stock” text on the single product page, but not the FULL string. In this particular case, not only I needed to change the text, but also edit the order of display: from “2 in stock” to “Quantity: 2“.

WooCommerce: in stock text in the single product page
WooCommerce: in stock text in the single product page

PHP Snippet: Change “# in stock” to “Quantity: #” @ WooCommerce Single Product Page

/**
 * @snippet       Display "Quantity: #" @ WooCommerce Single Product Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 4.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_filter( 'woocommerce_get_availability_text', 'bbloomer_custom_get_availability_text', 99, 2 );
 
function bbloomer_custom_get_availability_text( $availability, $product ) {
   $stock = $product->get_stock_quantity();
   if ( $product->is_in_stock() && $product->managing_stock() ) $availability = 'Quantity: ' . $stock;
   return $availability;
}
View Source
Posted in WooCommerce Tips