根据 Woocommerce 中的用户角色更改 COD 支付网关的默认订单状态
在 Woocommerce 中,当付款选项为 COD 时,订单会直接进入正在处理"状态.
In Woocommerce, when the payment option is COD, the orders go directly to the "Processing" state.
来源:https://docs.woocommerce.com/document/managing-订单/#prettyPhoto
我需要它像这样工作,除非客户的角色是X".
I need this to work like this, except when the client's role is "X".
我已经看到这可以通过以下代码解决:
I have seen that this can be solved with this code:
function cod_payment_method_order_status_to_onhold( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
if ( get_post_meta($order->id, '_payment_method', true) == 'cod' )
$order->update_status( 'on-hold' );
}
add_action( 'woocommerce_thankyou', 'cod_payment_method_order_status_to_onhold', 10, 1 );
然而,问题在于它经过处理",发送电子邮件,然后进入暂停"状态.我想避免发送处理中"邮件
However, the problem is that it goes through "Processing", sends the email and then goes to "on hold". I want to avoid sending the "Processing" mail
有什么办法吗?谢谢!
你最好使用 woocommerce_cod_process_payment_order_status
专用过滤钩子.您必须将管理员"用户角色替换为X"角色.
You should better use woocommerce_cod_process_payment_order_status
dedicated filter hook. You will have to replace "administrator" user role by your "X" role.
hook 函数代码:
add_filter( 'woocommerce_cod_process_payment_order_status', 'set_cod_process_payment_order_status_on_hold', 10, 2 );
function set_cod_process_payment_order_status_on_hold( $status, $order ) {
$user_data = get_userdata( $order->get_customer_id() );
if( ! in_array( 'administrator', $user_data->roles ) )
return 'on-hold';
return $status;
}
代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.