Hi Fred,
hanks for using my plugin! You are right I think this maybe a change in Woocommerce recently from what I have read as the plugin is running ‘wc_reduce_stock_levels()’.
It seems the payment status changes are now not allowing this function to run.
I will see what I can find out.
Cheers
J
Hi Jamie,
now ‘wc_reduce_stock_levels()’ checks if the stock has already been reduced for every order item (with the ‘_reduced_stock’ item meta) and if the stock reduction has already been fired on the order (with the ‘_order_stock_reduced’ post meta).
This is how i’ve fixed the issue:
// Reset stock reduction for new order items
foreach ( $order->get_items() as $item ) {
$item->delete_meta_data( ‘_reduced_stock’ );
}
// Reset stock reduction for new order
update_post_meta( $order_id, ‘_order_stock_reduced’, wc_bool_to_string( false ) );
// Reduce Order Stock
wc_reduce_stock_levels( $order_id );
// Set status to on hold as payment is not received
$order->update_status( ‘payment-pending’ );
Hi Giovan,
Seem to work like a charm nice fix. I will implement this and try get this released for you.
Thanks
J