Automattic\WooCommerce\StoreApi\Utilities

QuantityLimits::get_remaining_stock()protectedWC 1.0

Returns the remaining stock for a product if it has stock.

This also factors in draft orders.

Метод класса: QuantityLimits{}

Хуков нет.

Возвращает

Int|null.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_remaining_stock( $product );
$product(\WC_Product) (обязательный)
Product instance.

Код QuantityLimits::get_remaining_stock() WC 8.7.0

protected function get_remaining_stock( \WC_Product $product ) {
	if ( is_null( $product->get_stock_quantity() ) ) {
		return null;
	}

	$reserve_stock  = new ReserveStock();
	$reserved_stock = $reserve_stock->get_reserved_stock( $product, $this->get_draft_order_id() );

	return $product->get_stock_quantity() - $reserved_stock;
}