Skip to content

Commit

Permalink
Add filter to allow changing order stock reservation minutes (#45246)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninetyninew authored and Konamiman committed Mar 13, 2024
1 parent 622eb7c commit cd7c1fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 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.
11 changes: 11 additions & 0 deletions plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php
Expand Up @@ -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;
Expand Down

0 comments on commit cd7c1fa

Please sign in to comment.