删除woocommerce完成或基于订单元处理电子邮件 [英] Remove woocommerce complete or processing email based on order meta

查看:76
本文介绍了删除woocommerce完成或基于订单元处理电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据某些订单元删除正在处理(或完成)的电子邮件.

I am trying to remove the processing (or complete) email based on some order meta.

我正在使用POS系统,并通过客户发票电子邮件让客户付款-初始订单状态为待付款.我想a)测试订单是否使用pos进行,b)删除处理中"或完成"电子邮件.

I'm using a POS system and getting customers to pay via the customer invoice email - the initial order status is pending payment. I want to a) test if the order was made using the pos, b) remove either the "processing" or "complete" email.

我似乎无法使if语句逻辑起作用.我很确定meta键是'_pos',值是'1'或'0'.

I can't seem to get the if statement logic to work. I'm pretty sure the meta key is '_pos' and the value is '1' or '0'.

这是wp_postmeta的myphp屏幕截图

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' ) );
     }
}

我错过了什么吗?可以在woocommerce_email挂钩中使用post meta吗?

Am I missing something? Can post meta be used in the woocommerce_email hook?

如果我的if语句正确无误,我相信我可以删除正在处理/完整的电子邮件,甚至更改电子邮件类别并创建自定义处理电子邮件.

If I get the if statement correct I'm confident I can remove the processing/complete email or even change the email class and create a custom processing email.

推荐答案

更新(另一个与$ 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文件上.经过测试并可以正常工作.

This code goes on function.php file of your active child theme (or theme). tested and works.

相似的答案:避免在Woocommerce中针对特定产品类别的客户电子邮件通知

这篇关于删除woocommerce完成或基于订单元处理电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆