title: WooCommerce send new order email to customer
body: <p>I have a problem and it sounds stupid, but I'm really stucked. </p>
  
  <p>I need to send "new order" email also to customer. I tried adding function to functions.php file, and it sends email, but doesn't show most of variables. I inserted the same code into sample php file, added as page in wordpress and it works really well. I really don't know what is going on.</p>
  
  <p>Any solutions? Maybe there is more simple way, like adding recipent to "new order"email in woocommerce? I checked class-wc-email-new-order.php file, but I was not able to change anything in there, I don't understand how it works.</p>
  
  <p><a href="https://i.stack.imgur.com/bSw35.png" rel="nofollow noreferrer">screen: code working on page VS what is visible in received email</a> </p>
  
  <pre><code>      function create_email_body($order_id){
  
      global $woocommerce;
      if ( !$order_id )
      return;
      $order = new WC_Order( $order_id );
      $body = '';
      $product_list = '';
      $order_item = $order-&gt;get_items();
  
      foreach( $order_item as $product ) {
          $body .= $product['name']; 
      }
  
  $order = new WC_Order( $order_id );
  
  
  $body ='        &lt;div style = "width: 100%; clear: both;  color: #000;"&gt;';
  $body .='           &lt;div style="width: 50%; float: left;"&gt;';
  
  $body .='               &lt;p&gt; Numer zamówienia:&lt;b&gt; '. $order-&gt;get_order_number() .'&lt;/b&gt;   &lt;/p&gt;';
  $body .='               &lt;p&gt; Imię i nazwisko:&lt;b&gt; '. $order-&gt;billing_first_name . " " . $order-&gt;billing_last_name . '&lt;/b&gt; &lt;/p&gt;';
  $body .='               &lt;p&gt; Sposób dostawy: &lt;b&gt;  '. $order-&gt;get_shipping_method() .'&lt;/b&gt;    &lt;/p&gt;';
  $body .='               &lt;p&gt; Status zamówienia:&lt;b&gt;   przyjęte&lt;/b&gt;    &lt;/p&gt;';
  $body .='               &lt;p&gt; Adres dostawy: &lt;b&gt; '. $order-&gt;shipping_address_1 . " " . $order-&gt;shipping_address_2  . ", " . $order-&gt;shipping_postcode . " "    . $order-&gt;shipping_city . ", " . $order-&gt;shipping_state  . $order-&gt;shipping_country .'&lt;/b&gt; &lt;/p&gt;';
  
  $body .='           &lt;/div&gt;';
  $body .='           &lt;div style="width: 50%; float: left;"&gt;';
  
  $body .='               &lt;p&gt; Data zamówienia:&lt;b&gt; '. $order-&gt;order_date . '&lt;/b&gt;   &lt;/p&gt;';
  $body .='               &lt;p&gt; Email:  &lt;b&gt;&lt;span style = "color: #000 !important"&gt; '. $order-&gt;billing_email . '&lt;/b&gt; &lt;/span&gt;&lt;/p&gt; ';
  $body .='               &lt;p&gt; Metoda płatności: &lt;b&gt;    '. $order-&gt;payment_method_title .'&lt;/p&gt;';
  $body .='               &lt;p&gt; Numer telefonu:&lt;b&gt; '. $order-&gt;billing_phone .'&lt;/b&gt;  &lt;/p&gt;    ';
  $body .='           &lt;/div&gt;';
  $body .='       &lt;/div&gt;';
  $body .='       &lt;div style = "width: 100%; clear: both; color: #000; margin-top: 30px;"&gt;';
  
  $body .=' &lt;table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: "Myriad", sans-serif;" border="1"&gt;';
  $body .=' &lt;thead&gt;';
  $body .='   &lt;tr&gt;';
  $body .='       &lt;th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"&gt;&lt;/th&gt;';
  $body .='       &lt;th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"&gt;Produkt&lt;/th&gt;';
  $body .='       &lt;th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"&gt;Ilość&lt;/th&gt;';
  $body .='       &lt;th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"&gt;Cena&lt;/th&gt;';
  $body .='       &lt;th class="td" scope="col" style="text-align:left;" style = "border: none; color: #000;"&gt;Wartość&lt;/th&gt;';
  $body .='   &lt;/tr&gt;';
  $body .=' &lt;/thead&gt;';
  $body .=' &lt;tbody&gt;';
  
              $items = $order-&gt;get_items();
              foreach ( $items as $item_id =&gt; $item ) :
              $_product     = apply_filters( 'woocommerce_order_item_product', $order-&gt;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 .='               &lt;tr class=' . esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ) .'"&gt;';
  $body .='                   &lt;td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; word-wrap:break-word; color: #000;"&gt;';
  
  
  $body .='                   &lt;/td&gt;&lt;td style = "border: none; color: #000"&gt;';
                          // Product name
  $body .=$item['name'];///'                      &lt;p style = "display: inline-block; float: left"&gt;' . apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
                          if ( ! empty( $item_meta-&gt;meta ) ) {
  $body .=                             nl2br( $item_meta-&gt;display( true, true, '_', "\n" ) );
                          }
  $body .=                        "&lt;/p&gt;";
  
  $body .=                    '&lt;/td&gt;';
  
  $body .='                   &lt;td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000"&gt;' . apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ) .'&lt;/td&gt;';
  $body .='                   &lt;td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000"&gt;' . $_product-&gt;get_price();
  $body .='                   &lt;/td&gt;';
  $body .='                   &lt;td class="td" style="text-align:left; vertical-align:middle; border: none; font-family: "Myriad", sans-serif; color: #000"&gt;' . $order-&gt;get_formatted_line_subtotal( $item );
  $body .='               &lt;/td&gt;&lt;/tr&gt;';
  
              }
          endforeach; 
  
  $body .='               &lt;/tbody&gt;';
  $body .='               &lt;tfoot&gt;&lt;td style = "border: none;"&gt;&lt;/td&gt;&lt;td style = "border: none;"&gt;&lt;/td&gt;&lt;td style = "border: none; color: #000;"&gt;&lt;/td&gt;';
  $body .='                   &lt;td style = "border: none; color: #000;"&gt;';
  $body .='                       &lt;p&gt; Wartość produktów &lt;/p&gt; ';
  $body .='                       &lt;p&gt; Cena wysyłki &lt;/p&gt;';
  $body .='                       &lt;p&gt; Do zapłaty &lt;/p&gt;';
  $body .='                   &lt;/td&gt;';
  $body .='                   &lt;td style = "border: none; color: #000;"&gt;';
  $body .='                       &lt;p&gt;' . number_format((float)$order-&gt;get_subtotal(), 2, '.', '')  . " zł" . '&lt;/p&gt;';
  $body .='                       &lt;p&gt;' . number_format((float)$order-&gt;get_total_shipping(), 2, '.', '') . " zł" . '&lt;/p&gt;';
  $body .='                       &lt;p&gt;' . $order-&gt;get_formatted_order_total(). '&lt;/p&gt;';
  $body .='                   &lt;/td&gt;';
  $body .='               &lt;/tfoot&gt;';
  $body .='           &lt;/table&gt;';
  $body .='       &lt;/div&gt;';
  
  $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-&gt;billing_email;
  $headers = 'Od: AB.com &lt;a@b.com&gt;' . "\r\n";
  $mailer = WC()-&gt;mailer();
  $subject = 'Potwierdzenie przyjęcia zamówienia numer # ' . $order_id;
  $body = create_email_body($order_id);
  $mailer-&gt;send( $to_email, $subject, $mailer-&gt;wrap_message( $subject, $body), '', '' );
      }
      add_action( 'woocommerce_new_order', 'send_email_also_to_customer');
  </code></pre>