Add order note to display held stock inventory to provide more visibility to merchants.

This commit is contained in:
Abdalsalaam Halawa 2023-04-19 14:03:57 +02:00
parent b42da82e50
commit dbac9ff4d0
1 changed files with 8 additions and 0 deletions

View File

@ -72,6 +72,8 @@ final class ReserveStock {
return; return;
} }
$order_notes = array();
try { try {
$items = array_filter( $items = array_filter(
$order->get_items(), $order->get_items(),
@ -113,6 +115,7 @@ final class ReserveStock {
$item_quantity = apply_filters( 'woocommerce_order_item_quantity', $item->get_quantity(), $order, $item ); $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; $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 ) ) { if ( ! empty( $rows ) ) {
@ -124,6 +127,11 @@ final class ReserveStock {
$this->release_stock_for_order( $order ); $this->release_stock_for_order( $order );
throw $e; 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 ) );
}
} }
/** /**