title: how to send email after creating a woocommerce order programmatically
body: <p>I need to create a woocommerce order programmatically. I have this code in my <code>functions.php</code> file, it's working fine but I need to send an email when the order is saved before it's processed. How I can achive this, is there any woocommerce function that I can use ?</p>
  <pre class="lang-php prettyprint-override"><code>function order_product( $order_data ) 
  {
    $order_details = $order_data-&gt;get_params();
    $product_id = $order_details[&quot;product_id&quot;];
  
    $user_data = array(
      'first_name' =&gt; $order_details[&quot;name&quot;],
      'last_name'  =&gt; $order_details[&quot;cognome&quot;],
      'company'    =&gt; $order_details[&quot;societa&quot;],
      'email'      =&gt; $order_details[&quot;email&quot;],
      'phone'      =&gt; $order_details[&quot;telefono&quot;],
      'address_1'  =&gt; $order_details[&quot;indirizzo&quot;],
      'address_2'  =&gt; $oredr_details[&quot;indirizzo1&quot;],
      'city'       =&gt; $order_details[&quot;citta&quot;],
      'state'      =&gt; $order_details[&quot;provincia&quot;],
      'postcode'   =&gt; $order_details[&quot;cap&quot;],
      'country'    =&gt; $order_details[&quot;paese&quot;]
    );
  
    $new_order = wc_create_order();
    $new_order-&gt;add_product( get_product($product_id), 1 );
    $new_order-&gt;set_address( $user_data, &quot;billing&quot; );
    $new_order-&gt;calculate_totals();
    // Test
    return new WP_REST_Response( $order_details, 200 );
  }
  
  add_action( 'rest_api_init', function(){
    register_rest_route( 'shop/v1', '/checkout', array(
      'methods' =&gt; 'POST',
      'callback' =&gt; 'order_product'
    ), false );
  });
  </code></pre>