title: Woocomerce send custom email based on product purchased?
body: <p>I am trying to send a custom email based on product purchased other than completed order mail to customer.  </p>
  
  <pre><code>add_action( 'woocommerce_thankyou', 'my_function' );
  
  function my_function($order_id) {
     $order = new WC_Order( $order_id );
  
     foreach($order-&gt;get_items() as $item) {
        $_product = get_product($item['product_id']);
        if ($item['product_id']== 630) {
           $to_email = $order["billing_address"];
           $headers = 'From: Your Name &lt;your@email.com&gt;' . "\r\n";
           wp_mail($to_email, 'subject', 'message', $headers );
        }
      }
  }
  </code></pre>
  
  <p>It is not working. How do I fix it.</p>
  
  <p>Thanks</p>