I’m seeing exactly the same behaviour on our site as well. When I complete the order WooCommerce then adjusts the stock and deducts it from the overall total again. The stock levels for each branch stay the same and are correct.
Yeah… im just tied up with another priority work atm and then i’ll look into it again. Havent had time today. Meanwhile if you get a solution lemme know. Thanks
Adding this code to functions.php seems to prevent this extra stock deduction from happening, however it may also stop any other stock amendments from happening – refunds etc.
add_filter( 'woocommerce_prevent_adjust_line_item_product_stock', '__return_true' );
Hi @gferguson78 and @sikedelic
I will release a new version tomorrow fixing this issue.
Thanks Alex llooking forward to it
Fixed on the last release 1.4.1, please let me know if something wrong happens.
Hello Alex, hope you are well.
Thanks for the update and I can confirm that 1.4.1 fixes this issue. Welldone! However, if you could kindly extend yourself on my now new issue.
I am running a Market Place that means I have multiple Sellers. So, if an order comes in from a customer (example Order#1) which contains products from multiple sellers lets say 2 for this case. The Main order (order #1) is broken into suborders like (SubOrder #2) & (SubOrder #3) pls see this. SLW is deducting the stock from the Main Order which is okay cause that’s how it should work but it is also deducting stocks from the suborders which is duplicating the reduction. Please note that if and order comes in only containing products from one seller then EVERYTHING IS FINE.
Any help on this would be appreciated.
Thanks once again Alex!
Hi @sikedelic
Please create a new topic for this issue please.
Hey Alex thanks for getting back to me, managed to fix this issue just a couple of hours ago ;).
Hi @sikedelic
Can you share what you did?
Hello @alexmigf apologies I only saw this today.
I’m not sure if this is the best solution but what i did was let the suborder come in as a normal order and then restore the stocks. Please bear in mind that I am still learning php and no where near qualified lol. Might be a long read but see below if you wanna have a look. I hooked after (‘save_post_shop_order’) SLW is 10,3 Custom is 10,4.
//ADDED THIS CODE TO REVERSE BACK THE STOCK DEDUCTED IF A SUBORDER IS CREATED
add_action('save_post_shop_order','update_stock_locations_data_wc_order_save_custom',10,4);
function update_stock_locations_data_wc_order_save_custom($post_id,$post){
//GET AN INSTANCE OF WOOCOMMERCE $order OBJECT
$sub_order = wc_get_order( $post_id );
$parent_order = wp_get_post_parent_id( $sub_order->get_id());
//CHECK FOR PARENT
if ( ! $parent_order ) {
return;
}
//LOOP $sub_order ONLY IF $parent_order EXISTS
foreach ( $sub_order->get_items() as $sub_order_item_id => $sub_order_item ) {
if ( ! $sub_order_item->is_type( 'line_item' ) ) {
continue;
}
//WOOCOMMERCE PART
$sub_order_product_id = $sub_order_item->get_product_id();
$sub_order_qty = $sub_order_item->get_quantity();
$sub_order_current_stock = get_field('_stock',$sub_order_product_id);
//UPDATE
$sub_order_correct_stock = $sub_order_current_stock + $sub_order_qty;
update_post_meta($sub_order_product_id,'_stock',$sub_order_correct_stock);
if ($sub_order_correct_stock > 0) {
//UPDATE STATUS IN POSTMETA TABLE
update_post_meta($sub_order_product_id,'_stock_status','instock');
}
//SLW PART
$sub_order_slw_data = $sub_order_item->get_meta('_slw_data');
//LOOP THROUGH ARRAY DATA
foreach ($sub_order_slw_data as $sub_order_location_id => $sub_order_location ){
foreach ($sub_order_location as $key => $value){
$sub_order_quantity_subtracted = ($sub_order_location['quantity_subtracted']);
$sub_order_post_meta_key = '_stock_at_'.$sub_order_location_id;
$sub_order_current_stock_at_location = get_field($sub_order_post_meta_key,$sub_order_product_id);
$sub_order_updated_qty = $sub_order_current_stock_at_location + $sub_order_quantity_subtracted ;
//UPDATE
update_post_meta ($sub_order_product_id,$sub_order_post_meta_key,$sub_order_updated_qty);
}
}
}
}
If you have any suggestions or a better way i’d really appreciate it.
Very helpful @sikedelic
I found a bug with the main stock not being updated and will try use your code to manually fix this like you did.
Hi @phloo
Can you please share your code? I´m having the same issue that location stock can be deducted, but WC´s main stock remains the same.
My store is not multivendor and stock is deducted on locations by the store manager who decides from where an order should be shipped.
@ermosa hi
after many troubled hours with this plugin and the result that variations dont reduce correctly, we removed it completely and fixed our stocks again.
The author tried to help but didnt succeed. And I assume that the usage of the stock management on product level is just plain false (it ignores the stock of the variations)
Hi @phloo
Thanks for the quick reply! That’s unfortunate. I don´t have variable products and I kind of remember when installing the plugin, it did work correctly with my scenario: order comes in, shop manager assigns a location from where to deduct the product in the backend, with that, the stock is deducted from that location and also from the main stock. At the moment, it only deducts it from the location, but not from the main stock.