function revertStockReduction($wpla_order) { global $wpdb; if (!is_array($wpla_order['history'])) { return; } foreach ($wpla_order['history'] as $history_record) { // filter reduce_stock actions if ($history_record->action != 'reduce_stock') { continue; } // make sure purchased qty was recorded (since 0.9.2.8) $details = $history_record->details; if (!isset($details['qty_purchased'])) { continue; } $quantity_purchased = $details['qty_purchased']; // handle non-FBA quantity if (isset($details['quantity']) && isset($details['sku'])) { // get listing item $lm = new WPLA_ListingsModel(); $listing = $lm->getItemBySKU($details['sku']); // update quantity for FBA orders $quantity = $listing->quantity + $quantity_purchased; $quantity_sold = $listing->quantity_sold - $quantity_purchased; $wpdb->update($wpdb->prefix . 'amazon_listings', array('quantity' => $quantity, 'quantity_sold' => $quantity_sold), array('sku' => $details['sku'])); } // handle FBA quantity if (isset($details['fba_quantity']) && isset($details['sku'])) { // get listing item $lm = new WPLA_ListingsModel(); $listing = $lm->getItemBySKU($details['sku']); // update quantity for FBA orders $fba_quantity = $listing->fba_quantity + $quantity_purchased; $quantity_sold = $listing->quantity_sold - $quantity_purchased; $wpdb->update($wpdb->prefix . 'amazon_listings', array('fba_quantity' => $fba_quantity, 'quantity_sold' => $quantity_sold), array('sku' => $details['sku'])); } // handle WooCommerce quantity if (isset($details['product_id'])) { // increase product stock $post_id = $details['product_id']; $newstock = WPLA_ProductWrapper::increaseStockBy($post_id, $quantity_purchased, $wpla_order['order_id']); WPLA()->logger->info('increased product stock for #' . $post_id . ' by ' . $quantity_purchased . ' - new qty: ' . $newstock); // notify WP-Lister for eBay (and other plugins) do_action('wpla_inventory_status_changed', $post_id); } } // each history record }