Woocommerce stock reduction problem
-
Hello,
I changed how woocommerce reduces stock with following code snippet to fix a problem where customers abandoned orders, they turned to status “On-Hold” and stock was reduced. This code snippet worked perfectly until I updated to 3.5.0 – 3.5.2.
Code snippet:
// Woocommerce do not reduce stock on hold // add_filter( 'woocommerce_can_reduce_order_stock', 'wcs_do_not_reduce_onhold_stock', 10, 2 ); function wcs_do_not_reduce_onhold_stock( $reduce_stock, $order ) { if ( $order->has_status( 'on-hold' ) && $order->get_payment_method() == 'paysera' ) { $reduce_stock = false; } return $reduce_stock; } add_action( 'woocommerce_order_status_changed', 'order_stock_reduction_based_on_status', 20, 4 ); function order_stock_reduction_based_on_status( $order_id, $old_status, $new_status, $order ){ // Only for 'processing' and 'completed' order statuses change if ( $new_status == 'processing' || $new_status == 'completed' ){ $stock_reduced = get_post_meta( $order_id, '_order_stock_reduced', true ); if( empty($stock_reduced) && $order->get_payment_method() == 'paysera' ){ wc_reduce_stock_levels($order_id); } } }After updating to 3.5.0 and newer woocommerce. Now some orders, which go in following scheme do not reduce stock at all:
Pending payment -> On-Hold -> ProcessingDid anything change in 3.5.0 – 3.5.2 updates, which made my code snippet incorrect or this is some problem with my payment gateway(Paysera)?
Any help is appreciated,
Thanks,
Lukas
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Woocommerce stock reduction problem’ is closed to new replies.