2017-06-05 41 views
0

我PHP創建一個功能,我想三個參數如下傳遞到它:參數太少在WooCommerce電子郵件功能掛鉤

function lnz_wc_emails_memberreceipients($headers, $object, $order) { 

$company = $order->billing_company; 

$emailreturn = array (
    'Robin' => "[email protected]", 
    'Other' => "[email protected], [email protected]" 
); 

$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 

如果我刪除$對象OR $命令它工作得很好!但是,如果我嘗試幷包括它都會引發搖擺。

我能做些什麼來通過它所有三個?任何想法非常感謝。

回答

4

替換

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

+0

由於3個參數。奇蹟般有效。 –