Php 自定义WooCommerce电子邮件通知中的电子邮件标题

Php 自定义WooCommerce电子邮件通知中的电子邮件标题,php,wordpress,woocommerce,email-headers,email-notifications,Php,Wordpress,Woocommerce,Email Headers,Email Notifications,我正在尝试编写一个过滤器来更改WooCommerce电子邮件的回复地址,这取决于订单所针对的“计费城市” 这适用于WooCommerce电子邮件,但似乎不适用于WooCommerce高级通知-它似乎没有将“$order”传递到标题信息中以执行IF语句 这是一个很长的机会,但任何想法都值得赞赏。这是我的密码 function change_headers($order, $object, $headers); // Get the city $city = $order->get_bil

我正在尝试编写一个过滤器来更改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 <manchester@city.org>';
return $headers;
} else {
    $headers = array();
    $headers[] = 'Reply-to: London <london@city.org>';
return $headers;
}

add_filter( 'woocommerce_email_headers', 'change_headers', 10, 3);
进度编辑

所以现在基于Loic的善意建议,我已经应用了他的代码(如下),但启用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 

您已将函数中有关
woocommerce\u email\u标题的参数反转为
过滤器挂钩(注意:我不使用woocommerce高级通知插件)

相反,试试这个(我做了一些小改动):

add_filter('woocommerce_email_headers','custom_email_notification_headers',10,3);
函数自定义电子邮件通知头($headers,$email\u id,$order){
//占领城市
$city=$order->get_billing_city();
$headers=数组($headers);
如果($city=='Manchester')
{
$headers[]=“回复:曼彻斯特”;
}
其他的
{
$headers[]=“回复:伦敦”;
}
返回$headers;
}
代码位于活动子主题(或主题)的function.php文件或任何插件文件中


这段代码在WooCommerce版本3+上进行了测试,可以正常工作。

我已经进行了测试,但不幸的是,它不能与WooCommerce高级通知一起工作-我已经在上面的编辑中解释了原因。还有什么想法吗?!谢谢Loic。@LinzDarlington很抱歉你…你需要在这个插件源代码中找到一个过滤器钩子,因为它似乎没有使用经典的woocommerce核心函数或方法…@LoicTheAztec你能帮我解决这个问题吗@melvin你让我帮你处理代码…我已经尽我所能回答了,因为您的代码是不可测试的。@melvin,由于这种保密性,我无法提供正确的答案(那么,下次如果不清楚且不可测试,最好不要问我)。请记住:“寻求调试帮助的问题(“为什么此代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。”*。
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 
add_filter( 'woocommerce_email_headers', 'custom_email_notification_headers', 10, 3 );
function custom_email_notification_headers( $headers, $email_id, $order ) {

    // Get the city
    $city = $order->get_billing_city();

    $headers = array( $headers );

    if ($city == 'Manchester')
    {
        $headers[] = 'Reply-to: Manchester <manchester@city.org>';
    }
    else
    {
        $headers[] = 'Reply-to: London <london@city.org>';
    }
    return $headers;
}