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.
Method of the class: QuantityLimits{}
No Hooks.
Return
Int|null
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_remaining_stock( $product );
- $product(\WC_Product) (required)
- Product instance.
QuantityLimits::get_remaining_stock() QuantityLimits::get remaining stock code WC 9.6.1
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; }