当我们取消订单时,Woocommerce会自动重新进货。但我们不想自动重新进货,所以我尝试了这个钩子:
function filter_woocommerce_can_reduce_order_stock( $true, $order ) {
$stat = $order->get_status();
if($stat == \'cancelled\'){ // We want only disable restocking when status is cancelled.
$note = \'order stat is \'.$stat.\' so we do NOT updated the item stock.\';
$order->add_order_note( $note ); // To be make sure what happened.
return false; // Do not restock the product.
}else{
$note = \'order stat is \'.$stat.\' so we UPDATED the item stock.\';
$order->add_order_note( $note );
return true; // Restock the product.
}
}
add_filter( \'woocommerce_can_reduce_order_stock\',\'filter_woocommerce_can_reduce_order_stock\', 10, 2 );
也试过这个钩子:
add_filter( \'woocommerce_can_restore_order_stock\', \'ts_do_not_restock\', 10, 2 );
function ts_do_not_restock( $true, $order ){
$stat = $order->get_status();
if($stat == \'cancelled\'){
$note = \'order stat is \'.$stat.\' so we do not updated the item stock.\';
$order->add_order_note( $note ); // To be make sure what happened.
return false;
}else{
return true;
}
}
但这两种方法对我都不起作用,有没有办法禁用自动进货?