Fix stock reducing incorrect amount when order item is deleted after a refund closes #27504

This commit is contained in:
roykho 2020-10-22 13:32:22 -07:00 committed by Jonathan Sadowski
parent edb06be34e
commit 134786ada8
1 changed files with 8 additions and 0 deletions

View File

@ -218,6 +218,14 @@ function wc_maybe_adjust_line_item_product_stock( $item, $item_quantity = -1 ) {
$refunded_item_quantity = $order->get_qty_refunded_for_item( $item->get_id() ); $refunded_item_quantity = $order->get_qty_refunded_for_item( $item->get_id() );
$diff = $item_quantity + $refunded_item_quantity - $already_reduced_stock; $diff = $item_quantity + $refunded_item_quantity - $already_reduced_stock;
/*
* 0 as $item_quantity usually indicates we're deleting the order item.
* We need to perform different calculations for this case.
*/
if ( 0 === $item_quantity ) {
$diff = min( absint( $refunded_item_quantity ), $already_reduced_stock ) * -1;
}
if ( $diff < 0 ) { if ( $diff < 0 ) {
$new_stock = wc_update_product_stock( $product, $diff * -1, 'increase' ); $new_stock = wc_update_product_stock( $product, $diff * -1, 'increase' );
} elseif ( $diff > 0 ) { } elseif ( $diff > 0 ) {