首页 文章

在Woocommerce中向客户发送失败的订单电子邮件通知

提问于
浏览
1

我在我的主题functions.php文件中使用以下代码将订单失败的电子邮件仅发送给客户而不是管理员:

function wc_failed_order_email_to_customer( $recipient, $order ){
     return $recipient = $order->billing_email;
}
add_filter( 'woocommerce_email_recipient_failed_order', 'wc_failed_order_email_to_customer', 10, 2 );

它有效......

但我在php日志文件中收到以下错误:错误:billing_email被错误地调用 . 不应直接访问订单属性 . Backtrace:require('wp-blog-header.php'),require_once('wp-includes / template-loader.php'),do_action('template_redirect'),WP_Hook-> do_action,WP_Hook-> apply_filters,WC_AJAX :: do_wc_ajax,do_action('wc_ajax_checkout'),WP_Hook-> do_action,WP_Hook-> apply_filters,WC_AJAX :: checkout,WC_Checkout-> process_checkout,WC_Checkout-> process_order_payment,WC_Braintree \ Plugin_Framework \ SV_WC_Payment_Gateway_Direct-> process_payment,WC_Braintree \ Plugin_Framework \ SV_WC_Payment_Gateway_Direct-> do_transaction,WC_Braintree \ Plugin_Framework \ SV_WC_Payment_Gateway-> do_transaction_failed_result,WC_Braintree \ Plugin_Framework \ SV_WC_Payment_Gateway-> mark_order_as_failed,WC_Order-> update_status,WC_Order->保存,WC_Order-> status_transition,do_action( 'woocommerce_order_status_pending_to_failed'),WP_Hook-> do_action,WP_Hook-> apply_filters,WC_Emails :: send_transactional_email,do_action_ref_array,WP_Hook-> do_action,WP_Hook-> apply_filters,WC_Email_Failed_Order-> trigger,WC_Email-> get_recipient,apply_filt ers('woocommerce_email_recipient_failed_order'),WP_Hook-> apply_filters,wc_failed_order_email_to_customer,WC_Abstract_Legacy_Order - > __ get,wc_doing_it_wrong . 此消息已在3.0版中添加 .

我该如何解决这个错误?

1 回答

  • 0

    你需要用 WC_Order 方法 get_billing_email() 替换 billing_email ,如:

    add_filter( 'woocommerce_email_recipient_failed_order', 'wc_failed_order_email_to_customer', 10, 2 );
    function wc_failed_order_email_to_customer( $recipient, $order ){
         if( $billing_email = $order->get_billing_email() ) 
             recipient = $billing_email;
         return $recipient;
    }
    

    代码位于活动子主题(或活动主题)的function.php文件中 . 经过测试和工作 .

相关问题