Woocommerce inventory [closed]

The woocommerce_checkout_order_processed hook is too late. The order has already been created. You’d probably want to hook into woocommerce_after_checkout_validation so that you can check for the inventory before the order is even triggered and set an error that will be displayed at checkout.

By hooking in here, you will be able to short circuit the order creation with the error notice.

You can find more details about this in the WC_Checkout class.

See: https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-checkout.php#L849-L890