WooCommerce Code Reference

ReserveStock
in package

Stock Reservation class.

Table of Contents

$enabled  : bool
Is stock reservation enabled?
__construct()  : mixed
Constructor
get_reserved_stock()  : int
Query for any existing holds on stock for this item.
release_stock_for_order()  : mixed
Release a temporary hold on stock for an order.
reserve_stock_for_order()  : mixed
Put a temporary hold on stock for an order if enough is available.
is_enabled()  : bool
Is stock reservation enabled?
get_query_for_reserved_stock()  : string|void
Returns query statement for getting reserved stock of a product.
reserve_stock_for_product()  : mixed
Reserve stock for a product by inserting rows into the DB.

Properties

Methods

get_reserved_stock()

Query for any existing holds on stock for this item.

public get_reserved_stock(WC_Product $product, int $exclude_order_id) : int
Parameters
$product : WC_Product

Product to get reserved stock for.

$exclude_order_id : int

Optional order to exclude from the results.

Return values
intAmount of stock already reserved.

reserve_stock_for_order()

Put a temporary hold on stock for an order if enough is available.

public reserve_stock_for_order(WC_Order $order, int $minutes) : mixed
Parameters
$order : WC_Order

Order object.

$minutes : int

How long to reserve stock in minutes. Defaults to woocommerce_hold_stock_minutes.

Tags
throws
ReserveStockException

If stock cannot be reserved.

Return values
mixed

get_query_for_reserved_stock()

Returns query statement for getting reserved stock of a product.

private get_query_for_reserved_stock(int $product_id, int $exclude_order_id) : string|void
Parameters
$product_id : int

Product ID.

$exclude_order_id : int

Optional order to exclude from the results.

Return values
string|voidQuery statement.

reserve_stock_for_product()

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

private reserve_stock_for_product(int $product_id, int $stock_quantity, WC_Order $order, int $minutes) : mixed
Parameters
$product_id : int

Product ID which is having stock reserved.

$stock_quantity : int

Stock amount to reserve.

$order : WC_Order

Order object which contains the product.

$minutes : int

How long to reserve stock in minutes.

Tags
throws
ReserveStockException

If a row cannot be inserted.

Return values
mixed