我在PHP中创建一个函数,我想在下面传递三个参数:
function lnz_wc_emails_memberreceipients($headers, $object, $order) {
$company = $order->billing_company;
$emailreturn = array (
'Robin' => "weiltest@weiltest.com",
'Other' => "beistest@beistest.com, beistest2@beistest.com"
);
$headers = array();
$headers[] = 'Bcc: your name '.$emailreturn[$company];
$headers[] = 'Content-Type: text/html';
return $headers;
}
add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);
然而,当我尝试这样做时,我得到一个错误,表明我的函数要求3个参数,但只传递了两个。
Fatal error: Uncaught ArgumentCountError: Too few arguments to function lnz_wc_emails_memberreceipients(), 2 passed in /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php on line 300 and exactly 3 expected in /home/benefacto/public_html/dev3/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php:17 Stack trace: #0 /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php(300): lnz_wc_emails_memberreceipients('Content-Type: t...', 'customer_comple...') #1 /home/benefacto/public_html/dev3/wp-includes/plugin.php(203): WP_Hook->apply_filters('Content-Type: t...', Array) #2 /home/benefacto/public_html/dev3/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php(287): apply_filters('woocommerce_ema...', 'Content-Type: t...', 'customer_comple...', Object(WC_Order)) #3 /home/benefacto/public_html/dev3/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-completed-order.php(75): WC_Email->get_headers() #4 /home/benefacto/public_html/dev3/wp-includes/class-wp-hook.php(298): WC_Email in /home/benefacto/public_html/dev3/wp-content/plugins/bnfo-custom-emails/bnfo-custom-emails.php on line 17
如果我删除$ object OR $ order它就可以了!但是,如果我尝试将两者都包括在内,那就会摇摇欲坠。
我能做些什么来传递这三个吗?任何想法都非常感激。
答案 0 :(得分:6)
替换
add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);
用
add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 3);
接受过滤器woocommerce_email_headers