This code enables you to set a threshold for each product so the product displays out of stock if below your threshold or in stock if above the threshold.
In the demo video, we set a threshold of 100 for the product named Less Than 100. If the inventory goes below 100, the product displays as Out of Stock. The product named 50 In Stock only displays in stock if there’s 50 of more in stock, otherwise it displays out of stock.
You can add your threshold on any Edit product screen > Product Data > Simple Product > Inventory > Out of Stock Threshold :
There’s only 1 step : Copy & paste the PHP code ( without the opening PHP tag ) to the end of your child themes functions file or custom functionality plugin. You can then set the threshold on any Edit product screen using the Inventory tab.
Note : The download file also contains PHP code ( commented out ) which enables you to show stock levels offset by the threshold.