wc_get_held_stock_quantity()WC 3.5.0

See how much stock is being held in pending orders.

Hooks from the function

Return

Int.

Usage

wc_get_held_stock_quantity( $product, $exclude_order_id );
$product(WC_Product) (required)
Product to check.
$exclude_order_id(int)
Order ID to exclude.

Changelog

Since 3.5.0 Introduced.

wc_get_held_stock_quantity() code WC 8.7.0

function wc_get_held_stock_quantity( WC_Product $product, $exclude_order_id = 0 ) {
	/**
	 * Filter: woocommerce_hold_stock_for_checkout
	 * Allows enable/disable hold stock functionality on checkout.
	 *
	 * @since 4.3.0
	 * @param bool $enabled Default to true if managing stock globally.
	 */
	if ( ! apply_filters( 'woocommerce_hold_stock_for_checkout', wc_string_to_bool( get_option( 'woocommerce_manage_stock', 'yes' ) ) ) ) {
		return 0;
	}

	return ( new \Automattic\WooCommerce\Checkout\Helpers\ReserveStock() )->get_reserved_stock( $product, $exclude_order_id );
}