wc_reserve_stock_for_order()WC 4.1.0

Hold stock for an order.

Hooks from the function

Return

null. Nothing (null).

Usage

wc_reserve_stock_for_order( $order );
$order(\WC_Order|int) (required)
Order ID or instance.

Changelog

Since 4.1.0 Introduced.

wc_reserve_stock_for_order() code WC 8.7.0

function wc_reserve_stock_for_order( $order ) {
	/**
	 * Filter: woocommerce_hold_stock_for_checkout
	 * Allows enable/disable hold stock functionality on checkout.
	 *
	 * @since @since 4.1.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;
	}

	$order = $order instanceof WC_Order ? $order : wc_get_order( $order );

	if ( $order ) {
		( new \Automattic\WooCommerce\Checkout\Helpers\ReserveStock() )->reserve_stock_for_order( $order );
	}
}