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

时间:2018-12-10 00:55:53

标签: php wordpress woocommerce

我在主题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日志文件中遇到以下错误:

Error: billing_email was called incorrectly. Order properties should not be accessed directly. 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->save, 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_filters('woocommerce_email_recipient_failed_order'), WP_Hook->apply_filters, wc_failed_order_email_to_customer, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.

如何解决此错误?

1 个答案:

答案 0 :(得分:1)

您需要使用View方法billing_email替换WC_Order,例如:

get_billing_email()

代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。

相关问题