New order email is not sending for new clients in woocommerce

Hi there

If you met with problem when your clients don’t receive the letter about a new order after they complete the checkout form and you are using any plugin for modify the checkout form fields, and your checkout form doesn’t contain the field with name – billing_email, then you need to add this code to your functions.php:

function custom_billing_email_field($id, $recipient, $object)
{
	if(empty($object->billing_email))
	{
		return $_POST['your_custom_field_name'];
	}
	return $object->billing_email;
}

add_filter('woocommerce_email_recipient_customer_on_hold_order','custom_billing_email_field',10,3);

Where variable $_POST must contain your custom email field –

$_POST['your_custom_field_name']

.
And you need to use filter for your default type order status for new orders, in my case it is a hold status and filter –

woocommerce_email_recipient_customer_on_hold_order

.

But other filters also exists, they are formed from the concatenation strings – woocommerce_email_recipient_ and id of email WC_Email class in get_recipient() method:

	/**
	 * Get valid recipients.
	 * @return string
	 */
	public function get_recipient() {
		$recipient  = apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object );
		$recipients = array_map( 'trim', explode( ',', $recipient ) );
		$recipients = array_filter( $recipients, 'is_email' );
		return implode( ', ', $recipients );
	}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>