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
$enabled
Is stock reservation enabled?
private
bool
$enabled
= true
Methods
__construct()
Constructor
public
__construct() : mixed
Return values
mixed —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
int — Amount of stock already reserved.release_stock_for_order()
Release a temporary hold on stock for an order.
public
release_stock_for_order(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
Order object.
Return values
mixed —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
Return values
mixed —is_enabled()
Is stock reservation enabled?
protected
is_enabled() : bool
Return values
bool —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|void — Query 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.