Update restock logic during refunds closes #29502
This commit is contained in:
parent
e4fec5b914
commit
7105a7a17e
|
@ -454,6 +454,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
|
|||
'method_id',
|
||||
'cost',
|
||||
'_reduced_stock',
|
||||
'_restock_refunded_items',
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ $hidden_order_itemmeta = apply_filters(
|
|||
'method_id',
|
||||
'cost',
|
||||
'_reduced_stock',
|
||||
'_restock_refunded_items',
|
||||
)
|
||||
);
|
||||
?><div class="view">
|
||||
|
|
|
@ -206,17 +206,17 @@ function wc_maybe_adjust_line_item_product_stock( $item, $item_quantity = -1 ) {
|
|||
return false;
|
||||
}
|
||||
|
||||
$product = $item->get_product();
|
||||
$item_quantity = wc_stock_amount( $item_quantity >= 0 ? $item_quantity : $item->get_quantity() );
|
||||
$already_reduced_stock = wc_stock_amount( $item->get_meta( '_reduced_stock', true ) );
|
||||
$product = $item->get_product();
|
||||
$item_quantity = wc_stock_amount( $item_quantity >= 0 ? $item_quantity : $item->get_quantity() );
|
||||
$already_reduced_stock = wc_stock_amount( $item->get_meta( '_reduced_stock', true ) );
|
||||
$restock_refunded_items = wc_stock_amount( $item->get_meta( '_restock_refunded_items', true ) );
|
||||
|
||||
if ( ! $product || ! $product->managing_stock() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = $item->get_order();
|
||||
$refunded_item_quantity = $order->get_qty_refunded_for_item( $item->get_id() );
|
||||
$diff = $item_quantity + $refunded_item_quantity - $already_reduced_stock;
|
||||
$order = $item->get_order();
|
||||
$diff = $item_quantity - $restock_refunded_items - $already_reduced_stock;
|
||||
|
||||
/*
|
||||
* 0 as $item_quantity usually indicates we're deleting the order item.
|
||||
|
@ -238,7 +238,7 @@ function wc_maybe_adjust_line_item_product_stock( $item, $item_quantity = -1 ) {
|
|||
return $new_stock;
|
||||
}
|
||||
|
||||
$item->update_meta_data( '_reduced_stock', $item_quantity + $refunded_item_quantity );
|
||||
$item->update_meta_data( '_reduced_stock', $item_quantity - $restock_refunded_items );
|
||||
$item->save();
|
||||
|
||||
if ( $item_quantity > 0 ) {
|
||||
|
|
|
@ -715,9 +715,13 @@ function wc_restock_refunded_items( $order, $refunded_line_items ) {
|
|||
$item_stock_reduced = $item_stock_reduced - $qty_to_refund;
|
||||
|
||||
if ( 0 < $item_stock_reduced ) {
|
||||
// Keeps track of total running tally of reduced stock.
|
||||
$item->update_meta_data( '_reduced_stock', $item_stock_reduced );
|
||||
// Keeps track of only refunded items that needs restock.
|
||||
$item->update_meta_data( '_restock_refunded_items', $qty_to_refund );
|
||||
} else {
|
||||
$item->delete_meta_data( '_reduced_stock' );
|
||||
$item->delete_meta_data( '_restock_refunded_items' );
|
||||
}
|
||||
|
||||
/* translators: 1: product ID 2: old stock level 3: new stock level */
|
||||
|
|
Loading…
Reference in New Issue