根据订单元删除 woocommerce 完成或处理电子邮件
Remove woocommerce complete or processing email based on order meta
我正在尝试删除基于某些订单元的正在处理(或完成)的电子邮件。
我正在使用 POS 系统并让客户通过客户发票电子邮件付款 - 初始订单状态为待付款。我想 a) 测试订单是否是使用 pos 发出的,b) 删除 "processing" 或 "complete" 电子邮件。
我似乎无法使 if 语句逻辑起作用。我很确定元键是“_pos”,值是“1”或“0”。
Here's my myphp screem shot of wp_postmeta
add_action( 'woocommerce_email', 'removing_POS_emails' );
function removing_POS_emails( $email_class, $order_id ) {
//Remove the Processing email for POS emails
$pos_test = get_post_meta( $order_id, '_pos', true );
if ( $pos_test == "1" ) {
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
}
}
我错过了什么吗? post meta 可以用在 woocommerce_email hook 中吗?
如果我的 if 语句正确,我相信我可以删除 processing/complete 电子邮件,甚至更改电子邮件 class 并创建自定义处理电子邮件。
更新 (与 $order 参数相关的另一个挂钩上存在错误):
正确的做法是:
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'conditional_email_notification', 10, 2 );
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'conditional_email_notification', 10, 2 );
function conditional_email_notification( $recipient, $order ) {
if( is_admin() ) return $recipient;
if ( get_post_meta( $order->get_id(), '_pos', true ) ){
return '';
}
return $recipient;
}
此代码在您的活动子主题(或主题)的 function.php 文件中。 已测试并有效。
相似答案:Avoid customer email notification for a specific product category in Woocommerce
我正在尝试删除基于某些订单元的正在处理(或完成)的电子邮件。
我正在使用 POS 系统并让客户通过客户发票电子邮件付款 - 初始订单状态为待付款。我想 a) 测试订单是否是使用 pos 发出的,b) 删除 "processing" 或 "complete" 电子邮件。
我似乎无法使 if 语句逻辑起作用。我很确定元键是“_pos”,值是“1”或“0”。
Here's my myphp screem shot of wp_postmeta
add_action( 'woocommerce_email', 'removing_POS_emails' );
function removing_POS_emails( $email_class, $order_id ) {
//Remove the Processing email for POS emails
$pos_test = get_post_meta( $order_id, '_pos', true );
if ( $pos_test == "1" ) {
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
}
}
我错过了什么吗? post meta 可以用在 woocommerce_email hook 中吗?
如果我的 if 语句正确,我相信我可以删除 processing/complete 电子邮件,甚至更改电子邮件 class 并创建自定义处理电子邮件。
更新 (与 $order 参数相关的另一个挂钩上存在错误):
正确的做法是:
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'conditional_email_notification', 10, 2 );
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'conditional_email_notification', 10, 2 );
function conditional_email_notification( $recipient, $order ) {
if( is_admin() ) return $recipient;
if ( get_post_meta( $order->get_id(), '_pos', true ) ){
return '';
}
return $recipient;
}
此代码在您的活动子主题(或主题)的 function.php 文件中。 已测试并有效。
相似答案:Avoid customer email notification for a specific product category in Woocommerce