Correct comments in stock increase methods

Fixes some comments and a variable name in the stock increase methods.

There is however a logic problem remaining, I think, where the value taken for the per-item `_reduced_stock` meta value falls back to `true` when the meta key does not exists (line 266), however the key is deleted at the end of the loop (line 281), thus allowing the `wc_increase_stock_levels` methods to increase the stock again when re-run directly.
This commit is contained in:
Sören Schwert 2019-09-27 11:28:46 +02:00 committed by GitHub
parent aa665446e5
commit c22fcfd98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -121,16 +121,16 @@ function wc_maybe_increase_stock_levels( $order_id ) {
}
$stock_reduced = $order->get_data_store()->get_stock_reduced( $order_id );
$trigger_reduce = (bool) $stock_reduced;
$trigger_increase = (bool) $stock_reduced;
// Only continue if we're reducing stock.
if ( ! $trigger_reduce ) {
// Only continue if we're increasing stock.
if ( ! $trigger_increase ) {
return;
}
wc_increase_stock_levels( $order );
// Ensure stock is marked as "reduced" in case payment complete or other stock actions are called.
// Ensure stock is not marked as "reduced" anymore.
$order->get_data_store()->set_stock_reduced( $order_id, false );
}
add_action( 'woocommerce_order_status_cancelled', 'wc_maybe_increase_stock_levels' );
@ -261,7 +261,7 @@ function wc_increase_stock_levels( $order_id ) {
continue;
}
// Only reduce stock once for each item.
// Only increase stock once for each item.
$product = $item->get_product();
$item_stock_reduced = $item->get_meta( '_reduced_stock', true );