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 pageWooCommerce: 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 3.6.2
 */
 
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, 'woocommerce' );
  return $availability;
}
Share:

Leave a Reply