74
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“.
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://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;
}