Automattic\WooCommerce\StoreApi\Utilities
QuantityLimits::get_remaining_stock
Returns the remaining stock for a product if it has stock.
This also factors in draft orders.
Метод класса: QuantityLimits{}
Хуков нет.
Возвращает
int|float|null.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_remaining_stock( $product );
- $product(WC_Product) (обязательный)
- Product instance.
Код QuantityLimits::get_remaining_stock() QuantityLimits::get remaining stock WC 10.5.2
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 wc_stock_amount( $product->get_stock_quantity() - $reserved_stock );
}