Welcome back to WooCommerce Function of the Week! This week we cover a little hidden gem within the WooCommerce plugin code: wc_get_held_stock_quantity()
. As the name suggests, this function helps you get the amount of stock present in pending orders for a given product.
If your store relies on careful stock management β maybe because you handle products with a small inventory β wc_get_held_stock_quantity
is very useful. As orders come in for a limited number of products, you can take special action. Maybe you need to cancel those orders, or maybe you want to entice the customers placing them to complete their purchases before the item goes out of stock.
So, as usual, let’s first take a look at the function syntax and then consider a practical example of how you might use or display the returned value. Enjoy!