Don’t reduce stock on order status change to completed
-
add_filter( 'woocommerce_can_reduce_order_stock', 'can_reduce_order_stock_exceptions', 9000, 2 ); function can_reduce_order_stock_exceptions( $can_reduce, $order ) { // Define your product ID(s) or variation ID(s) that will avoid stock reduction $targeted_ids = array( 796 ); // Loop through order items foreach ( $order->get_items() as $item_id => $item ) { if ( in_array($item->get_product_id(), $targeted_ids) || in_array($item->get_variation_id(), $targeted_ids) ) { $can_reduce = false; break; } } return $can_reduce; }
If I create an order with any products + the product with id 796 and change the order status to completed it still reduces my product stock. I tried adding debug statements and it seems the function only gets called after creating the order and then changing the status to ‘Processing’.
But when I change the order status to ‘Completed’ it still reduces my stock. (No appearance in debug.log)
Is there a different filter I have to use for that?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Don’t reduce stock on order status change to completed’ is closed to new replies.