From cd7c1fa63356508b02ff8397f8a8af8e6e811344 Mon Sep 17 00:00:00 2001 From: 99w <56840277+ninetyninew@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:46:05 +0000 Subject: [PATCH] Add filter to allow changing order stock reservation minutes (#45246) --- plugins/woocommerce/changelog/45246-trunk | 4 ++++ .../woocommerce/src/Checkout/Helpers/ReserveStock.php | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 plugins/woocommerce/changelog/45246-trunk diff --git a/plugins/woocommerce/changelog/45246-trunk b/plugins/woocommerce/changelog/45246-trunk new file mode 100644 index 0000000000000..0c94517be5854 --- /dev/null +++ b/plugins/woocommerce/changelog/45246-trunk @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add `woocommerce_order_hold_stock_minutes` filter hook to allow the number of minutes stock in an order should be reserved for to be filtered. \ No newline at end of file diff --git a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php index 59cff93f63796..f7d2894ba2284 100644 --- a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php +++ b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php @@ -67,6 +67,17 @@ public function get_reserved_stock( $product, $exclude_order_id = 0 ) { */ public function reserve_stock_for_order( $order, $minutes = 0 ) { $minutes = $minutes ? $minutes : (int) get_option( 'woocommerce_hold_stock_minutes', 60 ); + /** + * Filters the number of minutes an order should reserve stock for. + * + * This hook allows the number of minutes that stock in an order should be reserved for to be filtered, useful for third party developers to increase/reduce the number of minutes if the order meets certain criteria, or to exclude an order from stock reservation using a zero value. + * + * @since 8.8.0 + * + * @param int $minutes How long to reserve stock for the order in minutes. Defaults to woocommerce_hold_stock_minutes or 10 if block checkout entry. + * @param \WC_Order $order Order object. + */ + $minutes = (int) apply_filters( 'woocommerce_order_hold_stock_minutes', $minutes, $order ); if ( ! $minutes || ! $this->is_enabled() ) { return;