How to display “Low Stock” instead of “Only x left in stock” on product page

Only x left in stock

If your product page displays the total number of inventory available once it reaches the Low Stock Threshold, there is a way to change that phrase to simply read “Low Stock”.

Add the following code snippet to your child theme’s functions.php file:

/* Change the 'Only # left in stock' message on the WooCommerce product page to
 * simply show 'Low Stock'.
 * Add to your theme's functions.php file
function custom_stock_totals($availability_html, $availability_text, $product) {
	if (substr($availability_text,0, 4)=="Only") {
		$availability_text = "Low Stock";
	$availability_html = '

‘ . esc_html( $availability_text ) . ‘

‘; return $availability_html; } add_filter(‘woocommerce_stock_html’, ‘custom_stock_totals’, 20, 3);

This is the result:

Low Stock

This solution assumes that your store is using the Stock Display Format as follows:

Stock Display Setting


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s