Support » Plugin: Email Log » PHP Warnings – Debug.log

  • Resolved KoolPal

    (@koolpal)


    Hi,

    I am getting the below PHP Notice in debug.log

    WP: 5.4.2
    Woocommerce: 4.2.0
    Email Log: 2.3.2

    [11-Jun-2020 11:32:25 UTC] PHP Notice: Array to string conversion in F:\laragon\www\iGMS\wp-content\plugins\email-log\include\Util\helper.php on line 171

    I am also seeing the below warnings:

    [11-Jun-2020 11:38:16 UTC] PHP Warning:  strpos() expects parameter 1 to be string, array given in F:\laragon\www\iGMS\wp-includes\pluggable.php on line 240
    [11-Jun-2020 11:38:16 UTC] PHP Warning:  trim() expects parameter 1 to be string, array given in F:\laragon\www\iGMS\wp-includes\pluggable.php on line 248
    [11-Jun-2020 11:38:16 UTC] PHP Notice:  Undefined offset: 1 in F:\laragon\www\iGMS\wp-includes\pluggable.php on line 248

    I am using the below code to change the Reply to address on outgoing emails.

    add_filter( 'woocommerce_email_headers', 'add_reply_to_certain_emails', 10, 2 );
    function add_reply_to_certain_emails ($headers, $object ) {
    	$add_reply_to = array(
    		'customer_on_hold_order',
    		'customer_processing_order',
    		'customer_completed_order',
    		'customer_refunded_order',
    		'customer_invoice',
    		'customer_note',
    		'customer_reset_password',
    		'customer_new_account',
    		);
    	if ( in_array( $object, $add_reply_to ) ) {
    		$headers = array( 
    			$headers,
    			'Reply-to: Domain.com <support@domain.com>' ."\r\n",
    			);
    	}
    	return $headers;

    Please review and guide me on what changes to make. Please let me know in case you require any additional information.

    Thanks a lot

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sudar Muthu

    (@sudar)

    Hello @koolpal

    The warning is happening because of an issue in your code and not because of WooCommerce or our Email Log plugin.

    Basically the problem is that the woocommerce_email_headers filter filters a string, but in your function you are converting it into an array. See https://github.com/woocommerce/woocommerce/blob/master/includes/emails/class-wc-email.php#L421 where this filter is getting used.

    You should change your function to the following and this will fix the issue for you.

    add_filter( 'woocommerce_email_headers', 'add_reply_to_certain_emails', 10, 2 );
    function add_reply_to_certain_emails ($headers, $object ) {
    	$add_reply_to = array(
    		'customer_on_hold_order',
    		'customer_processing_order',
    		'customer_completed_order',
    		'customer_refunded_order',
    		'customer_invoice',
    		'customer_note',
    		'customer_reset_password',
    		'customer_new_account',
    		);
    
    	if ( in_array( $object, $add_reply_to ) ) {
            $headers .= 'Reply-to: Domain.com <support@domain.com>' ."\r\n",
    	}
    	
        return $headers;
    }

    Try it out and let me know if you are still facing any issues.

    @sudar

    Thank you for replying.

    I tried your suggested code and I had to make the following changes to make this work
    1. Change , to ; at end of line 18
    2. Remove remove the . after $headers and change the line to $headers = in line 18

    line 18: $headers = 'Reply-to: Domain.com <support@domain.com>' ."\r\n";

    There are no more notices now!

    Thanks a lot!

    Plugin Author Sudar Muthu

    (@sudar)

    @koolpal

    Glad to know that you got it working.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Warnings – Debug.log’ is closed to new replies.