• Hi,
    Thank you for your great plugin, simple and efficient.
    I was wondering how I could send a copy CC of woocommerce on-hold-order email to client handler user, using :
    woocommerce_email_headers filter and address mail from $order->get_meta( ‘_billing_shop_as_client_handler_user_id’ );
    I tried many things but could not achieve this.

    Thank you for your help and your plugin

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @kosy33,

    Using the woocommerce_email_headers filter is exactly what we would recommend, then check if the order has the meta _billing_shop_as_client_handler_user_id and if it does, get its email address and add it to the Bcc header.

    Have you debugged this and check if the meta exists?
    I’m not exactly sure, but probably the issue is that the email is sent before we set that meta, but I would have to look into it further.

    Please be aware that our support is free, very limited, and does not include any custom development support.

    Thread Starter kosy33

    (@kosy33)

    Hi Marco,

    Thank you for your prompt answer and paying atention to my problem, yes the order has the meta, email is sent manually after checkout. At the moment I did not set any condition to $email_id. My code would be like this:

    `function filter_woocommerce_email_headers( $headers, $email_id, $order){
    $order_id = method_exists( $order, ‘get_id’ ) ? $order->get_id() : $order->id;
    $user_id = get_meta( $order_id,’_billing_shop_as_client_handler_user_id’ ,true);
    $user = get_user_by( ‘ID’, $user_id );

    $user_email = $user->user_email;

    // Get first & last name
    $user_name = $user->first_name . ‘ ‘;
    $user_name .= $user->last_name;

    // Prepare the the data
    $formatted_email = utf8_decode( $user_name . ‘ <‘ . $user_email . ‘>’ );

    // Add Cc to headers
    $headers .= ‘Cc: ‘ . $formatted_email . ‘\r\n’;
    }

    return $headers;
    }

    add_filter( ‘woocommerce_email_headers’, ‘filter_woocommerce_email_headers’, 10, 3);

    This code doesn not work, none email are sent.
    As my knowledge of coding is low your help would be welcome
    Thanks

    • This reply was modified 3 years, 2 months ago by kosy33.
    • This reply was modified 3 years, 2 months ago by kosy33.

    It seems ok but I would only add the $user_email and not the $user_name, and don’t utf8_decode() it. Also, I’m pretty sure \r\n should be inclosed in double quotes.

    Thread Starter kosy33

    (@kosy33)

    Marco,
    Thank you for these useful information, unfortunately I was not able to make it work.
    Following your advice code becomes

    function filter_woocommerce_email_headers( $headers, $email_id, $order){
    $order_id = method_exists( $order, ‘get_id’ ) ? $order->get_id() : $order->id;
    $user_id = get_meta( $order_id,’_billing_shop_as_client_handler_user_id’ ,true);
    $user = get_user_by( ‘ID’, $user_id );
    
    $user_email = $user->user_email;
    
    // Add Cc to headers
    $headers .= ‘Cc: ‘ . $user_email . "\r\n";
    
    return $headers;
    }
    
    add_filter( ‘woocommerce_email_headers’, ‘filter_woocommerce_email_headers’, 10, 3);

    email is sent to billing_email address but no cc to client handler user

    Thanks again having tried to help me; I will let you know if I can solve this issue
    Regards

    • This reply was modified 3 years, 2 months ago by kosy33.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘send on hold order email to clien handler user’ is closed to new replies.