From 7cb521ea3ce600b60f1bfd10206724ea37434d36 Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Fri, 1 Mar 2024 15:12:57 +0000 Subject: [PATCH 01/14] Update Checkout.php --- plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index ac08770b64fe..1d8ce807bf67 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -392,7 +392,7 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { */ try { $reserve_stock = new ReserveStock(); - $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : 10; + $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : apply_filters( 'woocommerce_hold_stock_minutes_checkout_draft', 10 ); $reserve_stock->reserve_stock_for_order( $this->order, $duration ); } catch ( ReserveStockException $e ) { throw new RouteException( From 3757991f901a6ff381786db08bc163508709af1e Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 1 Mar 2024 15:36:04 +0000 Subject: [PATCH 02/14] Add changefile(s) from automation for the following project(s): woocommerce --- plugins/woocommerce/changelog/45246-trunk | 4 ++++ 1 file changed, 4 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 000000000000..b4abb8d535c4 --- /dev/null +++ b/plugins/woocommerce/changelog/45246-trunk @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add `woocommerce_hold_stock_minutes_checkout_draft filter` hook to allow duration of stock reservation for checkout draft orders to be filtered \ No newline at end of file From f58704cf95464aa0f43fe5cacb91061427fb8b2b Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Fri, 1 Mar 2024 15:48:01 +0000 Subject: [PATCH 03/14] Add filter hook for draft order stock hold (#45245) --- .../src/StoreApi/Routes/V1/Checkout.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index 1d8ce807bf67..12a5f4e22c2a 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -391,9 +391,24 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { * If POSTing to the checkout (attempting to pay), set the timeout to 60 mins (using the woocommerce_hold_stock_minutes option). */ try { + $reserve_stock = new ReserveStock(); - $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : apply_filters( 'woocommerce_hold_stock_minutes_checkout_draft', 10 ); + + /** + * Filters the hold stock duration in minutes for draft orders on checkout entry. + * + * This hook filters the duration in minutes that stock is held for draft orders on checkout entry, it allows a third party to amend the duration to increase/reduce the time the stock is held for draft orders on checkout entry. + * + * @since 8.8.0 + * + * @param integer $minutes Minutes to hold stock for draft orders. + */ + + $draft_order_hold_stock_minutes = apply_filters( 'woocommerce_draft_order_hold_stock_minutes', 10 ); + + $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : $draft_order_hold_stock_minutes; $reserve_stock->reserve_stock_for_order( $this->order, $duration ); + } catch ( ReserveStockException $e ) { throw new RouteException( $e->getErrorCode(), From 3a6230587be5dcf21b51728244570c55926d11d0 Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Sun, 3 Mar 2024 15:22:12 +0000 Subject: [PATCH 04/14] Amending filter hook in changelog for draft order stock hold changes + filter comment amend (#45245) --- plugins/woocommerce/changelog/45246-trunk | 2 +- plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/changelog/45246-trunk b/plugins/woocommerce/changelog/45246-trunk index b4abb8d535c4..94223f73e30f 100644 --- a/plugins/woocommerce/changelog/45246-trunk +++ b/plugins/woocommerce/changelog/45246-trunk @@ -1,4 +1,4 @@ Significance: minor Type: add -Add `woocommerce_hold_stock_minutes_checkout_draft filter` hook to allow duration of stock reservation for checkout draft orders to be filtered \ No newline at end of file +Add `woocommerce_draft_order_hold_stock_minutes` filter hook to allow duration of stock reservation to hold stock for draft orders on checkout entry. \ No newline at end of file diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index 12a5f4e22c2a..210555f56b30 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -401,7 +401,7 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { * * @since 8.8.0 * - * @param integer $minutes Minutes to hold stock for draft orders. + * @param integer $minutes Minutes to hold stock for draft orders on checkout entry. */ $draft_order_hold_stock_minutes = apply_filters( 'woocommerce_draft_order_hold_stock_minutes', 10 ); From 96e4fe84a607963090670b93a4ddb441046b082c Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 3 Mar 2024 15:24:16 +0000 Subject: [PATCH 05/14] Add changefile(s) from automation for the following project(s): woocommerce --- plugins/woocommerce/changelog/45246-trunk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/changelog/45246-trunk b/plugins/woocommerce/changelog/45246-trunk index 94223f73e30f..b4abb8d535c4 100644 --- a/plugins/woocommerce/changelog/45246-trunk +++ b/plugins/woocommerce/changelog/45246-trunk @@ -1,4 +1,4 @@ Significance: minor Type: add -Add `woocommerce_draft_order_hold_stock_minutes` filter hook to allow duration of stock reservation to hold stock for draft orders on checkout entry. \ No newline at end of file +Add `woocommerce_hold_stock_minutes_checkout_draft filter` hook to allow duration of stock reservation for checkout draft orders to be filtered \ No newline at end of file From a219a59063977c1c730e3feb62cbb3661b7f6519 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 3 Mar 2024 20:49:40 +0000 Subject: [PATCH 06/14] Add changefile(s) from automation for the following project(s): woocommerce --- plugins/woocommerce/changelog/45246-trunk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/changelog/45246-trunk b/plugins/woocommerce/changelog/45246-trunk index b4abb8d535c4..f57b8efb1cd9 100644 --- a/plugins/woocommerce/changelog/45246-trunk +++ b/plugins/woocommerce/changelog/45246-trunk @@ -1,4 +1,4 @@ Significance: minor Type: add -Add `woocommerce_hold_stock_minutes_checkout_draft filter` hook to allow duration of stock reservation for checkout draft orders to be filtered \ No newline at end of file +Add `woocommerce_draft_order_hold_stock_minutes` filter hook to allow duration of stock reservation to hold stock for draft orders on checkout entry \ No newline at end of file From a4eab12e2a847e0f58cc04b91fd65314344c21d3 Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Mon, 4 Mar 2024 14:23:06 +0000 Subject: [PATCH 07/14] Add (int) to hook for draft order stock hold (#45245) --- plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index 210555f56b30..3767751f8578 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -404,7 +404,7 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { * @param integer $minutes Minutes to hold stock for draft orders on checkout entry. */ - $draft_order_hold_stock_minutes = apply_filters( 'woocommerce_draft_order_hold_stock_minutes', 10 ); + $draft_order_hold_stock_minutes = (int) apply_filters( 'woocommerce_draft_order_hold_stock_minutes', 10 ); $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : $draft_order_hold_stock_minutes; $reserve_stock->reserve_stock_for_order( $this->order, $duration ); From 10c87ba1af5a3df7b71bf6bf58cdb5dc00f97dee Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Tue, 5 Mar 2024 15:14:21 +0000 Subject: [PATCH 08/14] Fixing codesniff lint issues found on previous commits (#45245) --- plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index 3767751f8578..4cd3bc626bd8 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -403,10 +403,9 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { * * @param integer $minutes Minutes to hold stock for draft orders on checkout entry. */ - $draft_order_hold_stock_minutes = (int) apply_filters( 'woocommerce_draft_order_hold_stock_minutes', 10 ); - $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : $draft_order_hold_stock_minutes; + $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : $draft_order_hold_stock_minutes; $reserve_stock->reserve_stock_for_order( $this->order, $duration ); } catch ( ReserveStockException $e ) { From c361bfa3e0f423e7417adcb17de027a076fd7c6e Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Wed, 6 Mar 2024 14:10:10 +0000 Subject: [PATCH 09/14] Adding negative check to draft order hold stock minutes (#45245) --- plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index 4cd3bc626bd8..995db2b57229 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -392,7 +392,7 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { */ try { - $reserve_stock = new ReserveStock(); + $draft_order_hold_stock_minutes_default = 10; /** * Filters the hold stock duration in minutes for draft orders on checkout entry. @@ -403,8 +403,10 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { * * @param integer $minutes Minutes to hold stock for draft orders on checkout entry. */ - $draft_order_hold_stock_minutes = (int) apply_filters( 'woocommerce_draft_order_hold_stock_minutes', 10 ); + $draft_order_hold_stock_minutes = (int) apply_filters( 'woocommerce_draft_order_hold_stock_minutes', $draft_order_hold_stock_minutes_default ); + $draft_order_hold_stock_minutes = ( $draft_order_hold_stock_minutes >= 0 ? $draft_order_hold_stock_minutes : $draft_order_hold_stock_minutes_default ); + $reserve_stock = new ReserveStock(); $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : $draft_order_hold_stock_minutes; $reserve_stock->reserve_stock_for_order( $this->order, $duration ); From 9291ff09e3b69a10bbc25e0680e6fd972db9525b Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Thu, 7 Mar 2024 11:31:58 +0000 Subject: [PATCH 10/14] Discarding older changes in favour of PR recommendations (#45245) --- .../src/Checkout/Helpers/ReserveStock.php | 14 +++++++++++++- .../src/StoreApi/Routes/V1/Checkout.php | 18 +----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php index 59cff93f6379..1e7ed6a2881c 100644 --- a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php +++ b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php @@ -68,7 +68,19 @@ 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 ); - if ( ! $minutes || ! $this->is_enabled() ) { + /** + * Filters whether an order should allow stock to be reserved. + * + * This hook allows an order to be included/excluded from stock reservation, useful if a third party developer wants to exclude an order from having any stock reserved if the order meets certain criteria. + * + * @since 8.8.0 + * + * @param bool $reserve_stock_for_order If true, products in the order will have stock reserved if available. Default: true. + * @param \WC_Order $order Order object. + */ + $reserve_stock_for_order = apply_filters( 'woocommerce_reserve_stock_for_order', true, $order ); + + if ( ! $minutes || ! $reserve_stock_for_order || ! $this->is_enabled() ) { return; } diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php index 995db2b57229..ac08770b64fe 100644 --- a/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php +++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Checkout.php @@ -391,25 +391,9 @@ private function create_or_update_draft_order( \WP_REST_Request $request ) { * If POSTing to the checkout (attempting to pay), set the timeout to 60 mins (using the woocommerce_hold_stock_minutes option). */ try { - - $draft_order_hold_stock_minutes_default = 10; - - /** - * Filters the hold stock duration in minutes for draft orders on checkout entry. - * - * This hook filters the duration in minutes that stock is held for draft orders on checkout entry, it allows a third party to amend the duration to increase/reduce the time the stock is held for draft orders on checkout entry. - * - * @since 8.8.0 - * - * @param integer $minutes Minutes to hold stock for draft orders on checkout entry. - */ - $draft_order_hold_stock_minutes = (int) apply_filters( 'woocommerce_draft_order_hold_stock_minutes', $draft_order_hold_stock_minutes_default ); - $draft_order_hold_stock_minutes = ( $draft_order_hold_stock_minutes >= 0 ? $draft_order_hold_stock_minutes : $draft_order_hold_stock_minutes_default ); - $reserve_stock = new ReserveStock(); - $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : $draft_order_hold_stock_minutes; + $duration = $request->get_method() === 'POST' ? (int) get_option( 'woocommerce_hold_stock_minutes', 60 ) : 10; $reserve_stock->reserve_stock_for_order( $this->order, $duration ); - } catch ( ReserveStockException $e ) { throw new RouteException( $e->getErrorCode(), From c131ab9b2cc0e2ec722a956c13cb45895224d064 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 7 Mar 2024 11:39:25 +0000 Subject: [PATCH 11/14] Add changefile(s) from automation for the following project(s): woocommerce --- plugins/woocommerce/changelog/45246-trunk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/changelog/45246-trunk b/plugins/woocommerce/changelog/45246-trunk index f57b8efb1cd9..87ed278e40b9 100644 --- a/plugins/woocommerce/changelog/45246-trunk +++ b/plugins/woocommerce/changelog/45246-trunk @@ -1,4 +1,4 @@ Significance: minor Type: add -Add `woocommerce_draft_order_hold_stock_minutes` filter hook to allow duration of stock reservation to hold stock for draft orders on checkout entry \ No newline at end of file +Add `woocommerce_reserve_stock_for_order` filter hook to allow an order to be included/excluded from stock reservation. \ No newline at end of file From 8df29afd5b0aaf4eb04167baa7aefda10d2d84a9 Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Sat, 9 Mar 2024 12:10:46 +0000 Subject: [PATCH 12/14] Amends of woocommerce_order_hold_stock_minutes in favour of PR recommendations (#45245) --- .../woocommerce/src/Checkout/Helpers/ReserveStock.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php index 1e7ed6a2881c..14e6fc5b53dd 100644 --- a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php +++ b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php @@ -67,20 +67,19 @@ 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 whether an order should allow stock to be reserved. + * Filters the number of minutes an order should reserve stock for. * - * This hook allows an order to be included/excluded from stock reservation, useful if a third party developer wants to exclude an order from having any stock reserved if the order meets certain criteria. + * This hook allows the number of minutes stock in an order should be reserved for to be filtered, useful for third party developers to increase/reduce the number of minutes, or to exclude an order entirely if the order meets certain criteria. * * @since 8.8.0 * - * @param bool $reserve_stock_for_order If true, products in the order will have stock reserved if available. Default: true. + * @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. */ - $reserve_stock_for_order = apply_filters( 'woocommerce_reserve_stock_for_order', true, $order ); + $minutes = (int) apply_filters( 'woocommerce_order_hold_stock_minutes', $minutes, $order ); - if ( ! $minutes || ! $reserve_stock_for_order || ! $this->is_enabled() ) { + if ( ! $minutes || ! $this->is_enabled() ) { return; } From 35ba0bfc55081766fe842b223a2ad24e9a16a537 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 9 Mar 2024 12:15:32 +0000 Subject: [PATCH 13/14] Add changefile(s) from automation for the following project(s): woocommerce --- plugins/woocommerce/changelog/45246-trunk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/changelog/45246-trunk b/plugins/woocommerce/changelog/45246-trunk index 87ed278e40b9..0c94517be585 100644 --- a/plugins/woocommerce/changelog/45246-trunk +++ b/plugins/woocommerce/changelog/45246-trunk @@ -1,4 +1,4 @@ Significance: minor Type: add -Add `woocommerce_reserve_stock_for_order` filter hook to allow an order to be included/excluded from stock reservation. \ No newline at end of file +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 From 204180bcb04bf37f1d11a255caaadf954b074dae Mon Sep 17 00:00:00 2001 From: 99w <99w@99w.co.uk> Date: Mon, 11 Mar 2024 09:43:48 +0000 Subject: [PATCH 14/14] Amending woocommerce_order_hold_stock_minutes filter hook doc block comment (#45245) --- plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php index 14e6fc5b53dd..f7d2894ba228 100644 --- a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php +++ b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php @@ -70,7 +70,7 @@ public function reserve_stock_for_order( $order, $minutes = 0 ) { /** * Filters the number of minutes an order should reserve stock for. * - * This hook allows the number of minutes stock in an order should be reserved for to be filtered, useful for third party developers to increase/reduce the number of minutes, or to exclude an order entirely if the order meets certain criteria. + * 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 *