问题描述
我在网上搜索并查看了 WooCommerce docs 以找到一种解决方案,以禁用客户在 WooCoomerce 下订单时发送给他们的“确认电子邮件”。
但仅当订单具有自定义状态“mystatus”时,根据客户的订购情况,某些订单会获得该状态。
尝试像这样添加它,但它不起作用:
remove_action( 'woocommerce_order_status_mystatus_notification',array($email_class->emails['WC_Email_New_Order'],'trigger' ) );?>
有什么建议吗?
这是我更改特定订单的订单状态的方法:
add_action( 'woocommerce_thankyou','woocommerce_thankyou_change_order_status',10,1 );
function woocommerce_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();
if( ($order->get_status() == 'processing' || $order->get_status() == 'pending' || $order->get_status() == 'on-hold' ) && dokan_is_user_seller( $user_id ) && is_user_logged_in()) {
$order->update_status( 'mystatus' );
}
}
解决方法
禁用 WooCommerce >> Settings >> Emails
下的邮件,仅当您的订单具有自定义状态时才发送。
现在发送,以防您的订单状态正确:
add_action( 'woocommerce_thankyou','woocommerce_thankyou_change_order_status',10,1 );
function woocommerce_thankyou_change_order_status( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();
if ( ( $order->get_status() == 'processing' || $order->get_status() == 'pending' || $order->get_status() == 'on-hold' ) && dokan_is_user_seller( $user_id ) && is_user_logged_in() ) {
$order->update_status( 'mystatus' );
$email_oc = new WC_Email_Customer_Completed_Order();
$email_oc->trigger($order_id);
}
}
您可以从您想要的 PHP 发送每封 WooCommerce 邮件。
,无需对 WooCommerce 设置进行任何更改。
woocommerce_email_recipient_{$email_id}
过滤器是一个复合挂钩,通过设置正确的电子邮件 ID,您可以选择禁用电子邮件通知。
所以你得到:
// Admin - new order email notification
// Customer - on hold
// Customer - processing
// Customer - pending
function filter_woocommerce_email_recipient( $recipient,$order,$email ) {
if ( ! $order || ! is_a( $order,'WC_Order' ) ) return $recipient;
// Has order status
if ( $order->has_status( 'mystatus' ) ) {
$recipient = '';
}
return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order','filter_woocommerce_email_recipient',3 );
add_filter( 'woocommerce_email_recipient_customer_on_hold_order',3 );
add_filter( 'woocommerce_email_recipient_customer_processing_order',3 );
add_filter( 'woocommerce_email_recipient_customer_pending_order',3 );