Simon Davies Digital ltd

Show Woocommerce stock status for unmanaged products

Posted by Simon Davies & filed under WooCommerce, WordPress.

The WooCommerce stock status (In Stock, Out of stock) will only show if WooCommerce is managing the stock for you. I was working on a project and the client wanted the ability to manually set if the product was in stock or not. The code snippet below will allow you to show the stock status for both managed and unmanaged products. Just copy and paste into your themes functions.php file.
// Show the status for unmanaged stock products
add_filter( 'woocommerce_get_availability', 'show_stock_status_for_unmanaged_products', 1, 2);
function show_stock_status_for_unmanaged_products( $availability, $_product )
	// Don't do anything if managing stock
	if($_product->managing_stock()) return $availability;

	if($_product->is_in_stock()) :
		$availability['availability'] = __('In Stock', 'woocommerce');
		$availability['class'] = '';
	else :
		$availability['availability'] = __('Out of Stock', 'woocommerce');
		$availability['class'] = 'out-of-stock';

	return $availability;


Want to hear more about Mode and what we can do for your business or simply want to say hello, then get in touch.

+44 7846 400933
[email protected]