Add filter to allow changing order stock reservation minutes (#45246)

This commit is contained in:
99w 2024-03-11 16:46:05 +00:00 committed by GitHub
parent 7cc4094f4a
commit 0b6259edfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -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.

View File

@ -67,6 +67,17 @@ final class ReserveStock {
*/
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;