我正在嘗試編寫一個過濾器,用於更改WooCommerce電子郵件的回覆地址,具體取決於訂單所針對的「開票城市」。在WooCommerce電子郵件通知中自定義電子郵件標題
這適用於WooCommerce電子郵件,但似乎不適用於WooCommerce高級通知 - 它似乎沒有將'$ order'傳遞到標頭信息中以執行IF語句。
這是一個遠射,但任何想法非常感謝。這是我的代碼。
function change_headers($order, $object, $headers);
// Get the city
$city = $order->get_billing_city();
// Change Headers
if ($city == 'Manchester') {
$headers = array();
$headers[] = 'Reply-to: Manchester <[email protected]>';
return $headers;
} else {
$headers = array();
$headers[] = 'Reply-to: London <[email protected]>';
return $headers;
}
add_filter('woocommerce_email_headers', 'change_headers', 10, 3);
這是WooCommerce Advanced Notifications插件中的代碼。
/**
* sends an email through WooCommerce with the correct headers
*/
public function send($id, $object, $is_plain_text, $to, $subject, $message, $notification) {
$email = new WC_Email();
if ($is_plain_text) {
$message = wordwrap(strip_tags($message), 60);
$email->email_type = 'plain';
} else {
$email->email_type = 'html';
}
$email->id = "advanced_notification_{$notification->notification_id}";
$email->send($to, $subject, $message, $email->get_headers(), $email->get_attachments());
}
進展編輯
基於盧瓦克的樣的建議,所以我已申請了他的代碼(見下文),但在啓用WooCommerce高級聲明它拋出這個致命錯誤。這是因爲由於某種原因,'$ order'參數未正確傳遞到WooCommerce高級通知電子郵件的過濾器,所以$ city = $ order-> get_billing_city();是空的。
Fatal error: Uncaught Error: Call to a member function get_billing_city() on null in /home/benefacto/public_html/dev/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php:130 Stack trace: #0 /home/benefacto/public_html/dev/wp-includes/class-wp-hook.php(298): custom_email_notification_headers('Content-Type: t...', 'advanced_notifi...', NULL) #1 /home/benefacto/public_html/dev/wp-includes/plugin.php(203): WP_Hook->apply_filters('Content-Type: t...', Array) #2 /home/benefacto/public_html/dev/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php(287): apply_filters('woocommerce_ema...', 'Content-Type: t...', 'advanced_notifi...', NULL) #3 /home/benefacto/public_html/dev/wp-content/plugins/woocommerce-advanced-notifications/includes/class-wc-advanced-notifications.php(257): WC_Email->get_headers(NULL) #4 /home/benefacto/public_html/dev/wp-content/plugins/woocommerce-advanced-notifications/includes/class-wc-advanced-notifications.php(319): WC_Advanced_Notifications->send('new_order', Object(WC_Order), '0', 'l in /home/benefacto/public_html/dev/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php on line 130
感謝LoicTheAztec。我會用明亮的眼睛來測試明天,然後回覆。 –
我已經測試過,不幸的是它不適用於WooCommerce高級通知 - 我已經解釋了爲什麼在我上面編輯。任何進一步的想法?感謝Loic。 –
@LinzDarlington對不起,你...你應該需要在這個插件源代碼中找到一個過濾鉤,因爲它似乎不使用經典的woocommerce核心函數或方法... – LoicTheAztec