From dbac9ff4d05e799510f5f1ab8759f848218ea71b Mon Sep 17 00:00:00 2001 From: Abdalsalaam Halawa Date: Wed, 19 Apr 2023 14:03:57 +0200 Subject: [PATCH] Add order note to display held stock inventory to provide more visibility to merchants. --- plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php index 247e80a5255..24faa7699cd 100644 --- a/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php +++ b/plugins/woocommerce/src/Checkout/Helpers/ReserveStock.php @@ -72,6 +72,8 @@ final class ReserveStock { return; } + $order_notes = array(); + try { $items = array_filter( $order->get_items(), @@ -113,6 +115,7 @@ final class ReserveStock { $item_quantity = apply_filters( 'woocommerce_order_item_quantity', $item->get_quantity(), $order, $item ); $rows[ $managed_by_id ] = isset( $rows[ $managed_by_id ] ) ? $rows[ $managed_by_id ] + $item_quantity : $item_quantity; + $order_notes[] = $product->get_formatted_name() . ' : ' . $rows[ $managed_by_id ]; } if ( ! empty( $rows ) ) { @@ -124,6 +127,11 @@ final class ReserveStock { $this->release_stock_for_order( $order ); throw $e; } + + // Add order note after successfully holding the stock. + if ( ! empty( $rows ) ) { + $order->add_order_note( sprintf( __( 'Products stock held for %s minutes:', 'woocommerce' ), $minutes ) . ' ' . implode( ', ', $order_notes ) ); + } } /**