Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

“Only 3 left” when stock runs low

When 5 or fewer are left, the product page says “Only 3 left – order soon” instead of “3 in stock”.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Needs WooCommerce
  • Category WooCommerce
  • Tested with WordPress 7.1, WooCommerce 11.1
PHP
<?php

add_filter(
	'woocommerce_get_availability_text',
	static function ( $text, $product ) {
		$qty = $product->get_stock_quantity();
		if ( $product->managing_stock() && $product->is_in_stock() && null !== $qty && $qty > 0 && $qty <= 5 ) {
			return sprintf( 'Only %d left – order soon', $qty );
		}
		return $text;
	},
	10,
	2
);

Good to know

Needs stock management on the product. Change 5 and translate the message.

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.