以下减少库存的功能在WC 3.4.6之前运行良好,但是在更新到WC 3.5+之后,该功能不再有效。有想法吗?
//Reduce stock on processing & completed status
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( 'estimate' ) || $order->has_status( 'on-hold' ) || $order->has_status( 'pending' ) || $order->has_status( 'processing' ) ) {
$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 == 'completed' ){
$stock_reduced = get_post_meta( $order_id, '_order_stock_reduced', true );
if( empty($stock_reduced) ){
wc_reduce_stock_levels($order_id);
}
}
}