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

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

by adminkys

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 4.4
 * @donate $9     https://www.tutoraspire.com
 */
 
add_filter( 'woocommerce_get_availability_text', 'tutoraspire_custom_get_availability_text', 99, 2 );
 
function tutoraspire_custom_get_availability_text( $availability, $product ) {
   $stock = $product->get_stock_quantity();
   if ( $product->is_in_stock() && $product->managing_stock() ) $availability = 'Quantity: ' . $stock;
   return $availability;
}

You may also like