WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Automattic\WooCommerce\Checkout\Helpers

ReserveStock::reserve_stock_for_product() private WC 1.0

Reserve stock for a product by inserting rows into the DB.

Это метод класса: ReserveStock{}

Хуков нет.

Возвращает

Null. Ничего.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->reserve_stock_for_product( $product_id, $stock_quantity, $order, $minutes );
$product_id(число) (обязательный)
Product ID which is having stock reserved.
$stock_quantity(число) (обязательный)
Stock amount to reserve.
$order(\WC_Order) (обязательный)
Order object which contains the product.
$minutes(число) (обязательный)
How long to reserve stock in minutes.

Код ReserveStock::reserve_stock_for_product() WC 4.5.2

woocommerce/src/Checkout/Helpers/ReserveStock.php
<?php
private function reserve_stock_for_product( $product_id, $stock_quantity, $order, $minutes ) {
	global $wpdb;

	$product_data_store       = \WC_Data_Store::load( 'product' );
	$query_for_stock          = $product_data_store->get_query_for_stock( $product_id );
	$query_for_reserved_stock = $this->get_query_for_reserved_stock( $product_id, $order->get_id() );

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared
	$result = $wpdb->query(
		$wpdb->prepare(
			"
			INSERT INTO {$wpdb->wc_reserved_stock} ( `order_id`, `product_id`, `stock_quantity`, `timestamp`, `expires` )
			SELECT %d, %d, %d, NOW(), ( NOW() + INTERVAL %d MINUTE ) FROM DUAL
			WHERE ( $query_for_stock FOR UPDATE ) - ( $query_for_reserved_stock FOR UPDATE ) >= %d
			ON DUPLICATE KEY UPDATE `expires` = VALUES( `expires` ), `stock_quantity` = VALUES( `stock_quantity` )
			",
			$order->get_id(),
			$product_id,
			$stock_quantity,
			$minutes,
			$stock_quantity
		)
	);
	// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared

	if ( ! $result ) {
		$product = wc_get_product( $product_id );
		throw new ReserveStockException(
			'woocommerce_product_not_enough_stock',
			sprintf(
				/* translators: %s: product name */
				__( 'Not enough units of %s are available in stock to fulfil this order.', 'woocommerce' ),
				$product ? $product->get_name() : '#' . $product_id
			),
			403
		);
	}
}