2

I'm creating a function in PHP and I want to pass three arguments into it below:

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);

However, when I try and do this I get an error which suggests that my function is asking for 3 arguments but is only being passed two.

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

If I remove either $object OR $order it works just fine! But if I try and include both it throws the wobbly.

Is there anything I can do to pass it all three? Any thoughts much appreciated.

1 Answer 1

10

Replace

add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 2);

With

add_filter( 'woocommerce_email_headers', 'lnz_wc_emails_memberreceipients', 10, 3);

which accepts 3 arguments for the filter woocommerce_email_headers

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.