简体   繁体   中英

WooCommerce - Order Status for Pending Payment Reducing Stock

I use WooCommerce to manually take orders via the telephone / email etc. I use the backend to record the orders manually adding the orders.

At present, when generating an order as 'pending payment' as the status the stock is automatically reduced / deducted. I do not want this to happen. Ideally I only want stock to be reduced when the order is marked as in 'processing' as then payment would of then been taken.

I understand this is how WooCommerce works back is there a way to avoid stock being reduced until a certain status has been selected?

I have tried the below code within functions.php and used the 'on-hold' status to test but the stock is still reduced.

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' )) {
        $reduce_stock = false;
    }
    return $reduce_stock;
}

I wonder if it because I am adding the order as an admin? I know this is how WooCommerce works but ideally I need a method of overriding the 'pending payment' status when creating an order both within the draft and creation stage until marked as 'processing'.

Any help would be fantastic.

Try this adding to functions.php Note: not tested.

function reduce_stock_processing($order_id) {
 wc_reduce_stock_levels($order_id);

}

add_action('woocommerce_order_status_processing', 'reduce_stock_processing');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM