Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hello @abitp,

    What’s the issue you’re encountering that’s different from anything outlined in that thread?

    Thread Starter ITP TECHNOLOGIE

    (@abitp)

    I successfully copied and pasted the code into my function.php file, and I changed the code from:
    $extra_email_address = $order->get_meta( ‘extra_email_address’ )
    to :
    $extra_email_address = $order->get_meta( ‘b2bking_custom_field_171853’ )
    However, when I create an invoice, it is not being sent to the address I entered in the custom field.

    Thread Starter ITP TECHNOLOGIE

    (@abitp)

    my new code doesn’t works

    add_filter( 'woocommerce_email_headers', 'woocommerce_emails_bcc_copy', 10, 3);
    function woocommerce_emails_bcc_copy( $headers, $email_id, $order, $email = null ) {
    // Si la notification par e-mail est "Completed order" ou "Processing order"
    if ( in_array( $email_id, array('customer_completed_order', 'customer_processing_order') ) ) {
    // Remplacez 'b2bking_custom_field_171853' par la clé de métadonnées réelle de votre champ personnalisé
    if ( $extra_email_address = get_user_meta( $order->get_user_id(), 'b2bking_custom_field_171853', true ) ) {
    $billing_full_name = $order->get_formatted_billing_full_name();
    $headers .= 'BCC: ' . $billing_full_name . ' <' . $extra_email_address . '>' . "\r\n";
    }
    }
    return $headers;
    }

    Plugin Contributor dwpriv

    (@dwpriv)

    @abitp can you confirm that ‘b2bking_custom_field_171853‘ is the name of the meta field saved to the order? You can use this guide to check.

    Thread Starter ITP TECHNOLOGIE

    (@abitp)

    Yes is a good name ! ( i use B2Bking for create this field )

    Plugin Contributor dwpriv

    (@dwpriv)

    @abitp

    Give this one a try:

    
    
    add_filter( 'woocommerce_email_headers', 'woocommerce_emails_bcc_copy', 10, 3);
    
    function woocommerce_emails_bcc_copy( $headers, $email_id, $order, $email = null ) {
    
        // Si la notification par e-mail est "Completed order" ou "Processing order"
    
        if ( in_array( $email_id, array('customer_completed_order', 'customer_processing_order') ) ) {
    
            // Remplacez 'b2bking_custom_field_171853' par la clé de métadonnées réelle de votre champ personnalisé
    
            if ( $extra_email_address = $order->get_meta( 'b2bking_custom_field_171853' ) ) {
    
                $billing_full_name = $order->get_formatted_billing_full_name();
    
                $headers .= 'BCC: ' . $billing_full_name . ' <' . $extra_email_address . '>' . "\r\n";
    
            }
    
        }
    
        return $headers;
    
    }
    
    
    Thread Starter ITP TECHNOLOGIE

    (@abitp)

    doesn’t works 🙁

    Thread Starter ITP TECHNOLOGIE

    (@abitp)

    up

    Plugin Contributor dwpriv

    (@dwpriv)

    @abitp

    Could you share a screenshot of the order meta data showing how the b2b meta key is saved, please?

    Thread Starter ITP TECHNOLOGIE

    (@abitp)

    Okay, I managed to get it working with the developers of the B2BKING plugin. Now, I have a problem because no emails are being sent or received when an order is in the status ‘In preparation’…

    
    function woocommerce_emails_bcc_copy( $headers, $email_id, $order, $email = null ) {
        if ( in_array( $email_id, array('customer_refunded_order', 'customer_completed_order') ) ) {
            if ( $extra_email_address = $order->get_meta( 'b2bking_custom_field_171853' ) ) {
                $billing_full_name = $order->get_formatted_billing_full_name();
    			$headers .= 'BCC: ' . $billing_full_name . ' <' . $extra_email_address . '> ' . "\r\n";
            }
        }
        return $headers;
    }
    add_filter( 'woocommerce_email_headers', 'woocommerce_emails_bcc_copy', 10, 3);
    Plugin Contributor dwpriv

    (@dwpriv)

    @abitp

    You can add a check for the status. I have added it

    
    
    function woocommerce_emails_bcc_copy( $headers, $email_id, $order, $email = null ) {
    
        if ( in_array( $email_id, array('customer_refunded_order', 'customer_completed_order') ) ) {
    
            if ( $extra_email_address = $order->get_meta( 'b2bking_custom_field_171853' ) && $order->get_status() != 'preparation' ) {
    
                $billing_full_name = $order->get_formatted_billing_full_name();
    
                $headers .= 'BCC: ' . $billing_full_name . ' <' . $extra_email_address . '> ' . "\r\n";
    
            }
    
        }
    
        return $headers;
    
    }
    
    add_filter( 'woocommerce_email_headers', 'woocommerce_emails_bcc_copy', 10, 3);
    
    

    I used the status name ‘preparation’. this will likely need to be changed to the actual name of the status.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Double email invoice’ is closed to new replies.