• Resolved phareweb35

    (@phareweb35)


    Hi !

    For my Woocommerce store, I need to send an order email to a third party recipient. I used this code in my functions.php to do so :

    /***************/

    function add_third_party_email( $recipient, $order ) {
    global $woocommerce;
    $items = $order->get_items();
    foreach ( $items as $item ) {
    $product_id = $item['product_id'];
    $rechargeable_id = get_wallet_rechargeable_product()->get_id();
    // We check if the product is not Wallet recharge or AGRI / TP / PL
    if ( $product_id !== 4299 && $product_id !== $rechargeable_id ) {
    $additional_email1 = '[email protected]';
    if ( ! empty( $additional_email1 ) ) {
    $recipient .= ',' . $additional_email1 ;
    }
    return $recipient;
    }
    }
    }
    add_filter( 'woocommerce_email_recipient_new_order', 'add_third_party_email', 10, 2 );

    /****************/

    However, the problem I’m facing now is that I don’t want the third party recipient to have the PDF invoice attached to the order email.

    Do you have a solution / code snippet to had to my function in order to achieve this ?

    Thanks for your support.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter phareweb35

    (@phareweb35)

    Any way to fix this ? Still waiting for a reply.

    Best regards.

    Paul

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @phareweb35

    Sorry for the late reply!

    Please add the code snippet below:

    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type, $output_format ) {
    	if ( 'new_order' === $email_id ) {
    		$emails = WC()->mailer()->get_emails();
    	
    		if ( isset( $emails[ $email_id ] ) ) {
    			$email     = $emails[ $email_id ];
    			$recipient = $email->get_recipient();
    			
    			if ( ! empty( $recipient ) && strpos( $recipient, '[email protected]' ) !== false ) {
    				$attach = false;
    			}
    		}
    	}
    }, 10, 5 );

    I have considered the same recipient email from your code snippet. Please note that this code snippet will disable the attachment for the email, so the admin will not get the attachment too.

    Alternatively you could use our Professional extension feature: Order Notification email

    Let me know.

    • This reply was modified 5 months, 4 weeks ago by alexmigf.
    Thread Starter phareweb35

    (@phareweb35)

    Hi,

    Thanks for support.

    I pasted your code snippet bellow mine (the one in my original support question). It works, the additional recipient email doesn’t get the PDF invoice attached to the confirmation mail, but the client also doesn’t get the PDF.

    I just need the additional recipient email to be the only one to NOT receive the PDF invoice.

    Thanks for your help.

    Paul

    Plugin Contributor Mohamad

    (@mohamadntr)

    Hi @phareweb35

    Could you replace that code with this:

    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type, $output_format ) {
    if ( 'new_order' === $email_id ) {
    $emails = WC()->mailer()->get_emails();

    if ( isset( $emails[ $email_id ] ) ) {
    $email = $emails[ $email_id ];
    $recipient = $email->get_recipient();

    if ( ! empty( $recipient ) && strpos( $recipient, '[email protected]' ) !== false ) {
    $attach = false;
    }
    }
    }

    return $attach;
    }, 10, 5 );

    I made a slight adjustment, and I think it works now.

    Best regards

    Thread Starter phareweb35

    (@phareweb35)

    Hi,

    Still not working, this time, the additional recipient email is receiving the invoice. Here is what I have in my functions.php :

    /* Send order to third party email */
    function add_third_party_email($recipient, $order)
    {
    global $woocommerce;
    $items = $order->get_items();
    foreach ($items as $item) {
    $product_id = $item[‘product_id’];
    $rechargeable_id = get_wallet_rechargeable_product()->get_id();
    // We check if the product is not Wallet recharge or AGRI / TP / PL
    if ($product_id !== 4299 && $product_id !== $rechargeable_id) {
    $additional_email1 = ‘[email protected]’;
    if (!empty($additional_email1)) {
    $recipient .= ‘,’ . $additional_email1;
    }
    return $recipient;
    }
    }
    }
    add_filter(‘woocommerce_email_recipient_new_order’, ‘add_third_party_email’, 10, 2);

    add_filter( ‘wpo_wcpdf_custom_attachment_condition’, function( $attach, $order, $email_id, $document_type, $output_format ) {
    if ( ‘new_order’ === $email_id ) {
    $emails = WC()->mailer()->get_emails();

        if ( isset( $emails[ $email_id ] ) ) {
            $email     = $emails[ $email_id ];
            $recipient = $email->get_recipient();
    
            if ( ! empty( $recipient ) && strpos( $recipient, '[email protected]' ) !== false ) {
                $attach = false;
            }
        }
    }
    
    return $attach;

    }, 10, 5 );

    Thanks again for your help.

    Plugin Contributor Mohamad

    (@mohamadntr)

    Hi @phareweb35

    Could you give this code a try please:

    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type, $output_format ) {
    if ( 'new_order' === $email_id ) {
    $emails = WC()->mailer()->get_emails();

    if ( isset( $emails[ 'WC_Email_New_Order' ] ) ) {
    $email = $emails[ 'WC_Email_New_Order' ];
    $recipient = $email->get_recipient();

    if ( ! empty( $recipient ) && strpos( $recipient, '[email protected]' ) !== false ) {
    $attach = false;
    }
    }
    }

    return $attach;
    }, 10, 5 );

    Thread Starter phareweb35

    (@phareweb35)

    It works !

    Thanks a lot for your support.

    Plugin Contributor Mohamad

    (@mohamadntr)

    You’re welcome! Glad to hear it works!

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.