WooCommerce envia novo e-mail de pedido ao cliente

Eu tenho um problema e parece estúpido, mas estou realmente preso.

Também preciso enviar um email de "novo pedido" ao cliente. Tentei adicionar funções ao arquivo functions.php e ele envia email, mas não mostra a maioria das variáveis. Eu inseri o mesmo código no arquivo php de amostra, adicionado como página no wordpress e funciona muito bem. Eu realmente não sei o que está acontecendo.

Alguma solução? Talvez exista uma maneira mais simples, como adicionar destinatário ao e-mail de "novo pedido" no woocommerce? Eu verifiquei o arquivo class-wc-email-new-order.php, mas não consegui alterar nada, não entendo como funciona.

tela: código trabalhando na página VS o que é visível no email recebido

      function create_email_body($order_id){

    global $woocommerce;
    if ( !$order_id )
    return;
    $order = new WC_Order( $order_id );
    $body = '';
    $product_list = '';
    $order_item = $order->get_items();

    foreach( $order_item as $product ) {
        $body .= $product['name']; 
    }

$order = new WC_Order( $order_id );


$body ='        <div style = "width: 100%; clear: both;  color: #000;">';
$body .='           <div style="width: 50%; float: left;">';

$body .='               <p> Numer zamówienia:<b> '. $order->get_order_number() .'</b>   </p>';
$body .='               <p> Imię i nazwisko:<b> '. $order->billing_first_name . " " . $order->billing_last_name . '</b> </p>';
$body .='               <p> Sposób dostawy: <b>  '. $order->get_shipping_method() .'</b>    </p>';
$body .='               <p> Status zamówienia:<b>   przyjęte</b>    </p>';
$body .='               <p> Adres dostawy: <b> '. $order->shipping_address_1 . " " . $order->shipping_address_2  . ", " . $order->shipping_postcode . " "    . $order->shipping_city . ", " . $order->shipping_state  . $order->shipping_country .'</b> </p>';

$body .='           </div>';
$body .='           <div style="width: 50%; float: left;">';

$body .='               <p> Data zamówienia:<b> '. $order->order_date . '</b>   </p>';
$body .='               <p> Email:  <b><span style = "color: #000 !important"> '. $order->billing_email . '</b> </span></p> ';
$body .='               <p> Metoda płatności: <b>    '. $order->payment_method_title .'</p>';
$body .='               <p> Numer telefonu:<b> '. $order->billing_phone .'</b>  </p>    ';
$body .='           </div>';
$body .='       </div>';
$body .='       <div style = "width: 100%; clear: both; color: #000; margin-top: 30px;">';

$body .=' <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: "Myriad", sans-serif;" border="1">';
$body .=' <thead>';
$body .='   <tr>';
$body .='       <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"></th>';
$body .='       <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Produkt</th>';
$body .='       <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Ilość</th>';
$body .='       <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Cena</th>';
$body .='       <th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;">Wartość</th>';
$body .='   </tr>';
$body .=' </thead>';
$body .=' <tbody>';

            $items = $order->get_items();
            foreach ( $items as $item_id => $item ) :
            $_product     = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
            $item_meta    = new WC_Order_Item_Meta( $item, $_product );

            if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {

$body .='               <tr class=' . esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ) .'">';
$body .='                   <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; word-wrap:break-word; color: #000;">';


$body .='                   </td><td style = "border: none; color: #000">';
                        // Product name
$body .=$item['name'];///'                      <p style = "display: inline-block; float: left">' . apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
                        if ( ! empty( $item_meta->meta ) ) {
$body .=                             nl2br( $item_meta->display( true, true, '_', "\n" ) );
                        }
$body .=                        "</p>";

$body .=                    '</td>';

$body .='                   <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ) .'</td>';
$body .='                   <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . $_product->get_price();
$body .='                   </td>';
$body .='                   <td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000">' . $order->get_formatted_line_subtotal( $item );
$body .='               </td></tr>';

            }
        endforeach; 

$body .='               </tbody>';
$body .='               <tfoot><td style = "border: none;"></td><td style = "border: none;"></td><td style = "border: none; color: #000;"></td>';
$body .='                   <td style = "border: none; color: #000;">';
$body .='                       <p> Wartość produktów </p> ';
$body .='                       <p> Cena wysyłki </p>';
$body .='                       <p> Do zapłaty </p>';
$body .='                   </td>';
$body .='                   <td style = "border: none; color: #000;">';
$body .='                       <p>' . number_format((float)$order->get_subtotal(), 2, '.', '')  . " zł" . '</p>';
$body .='                       <p>' . number_format((float)$order->get_total_shipping(), 2, '.', '') . " zł" . '</p>';
$body .='                       <p>' . $order->get_formatted_order_total(). '</p>';
$body .='                   </td>';
$body .='               </tfoot>';
$body .='           </table>';
$body .='       </div>';

$body .= file_get_contents(get_stylesheet_directory_uri() . '/woocommerce/emails/customer-on-hold.order.php');

return $body;
    } 

    function send_email_also_to_customer($order_id){

$order = new WC_Order( $order_id );

$to_email = $order->billing_email;
$headers = 'Od: AB.com <[email protected]>' . "\r\n";
$mailer = WC()->mailer();
$subject = 'Potwierdzenie przyjęcia zamówienia numer # ' . $order_id;
$body = create_email_body($order_id);
$mailer->send( $to_email, $subject, $mailer->wrap_message( $subject, $body), '', '' );
    }
    add_action( 'woocommerce_new_order', 'send_email_also_to_customer');

questionAnswers(3)

yourAnswerToTheQuestion