I am using the WooCommerce Follow Up Emails plugin to design a custom email to be sent after an order is made.
The product that is being ordered has a few Add On Fields displayed that are populated when the customer makes the order. One of the fields is an email address.
I want to send the custom follow up email I've designed to the email address provided in the field rather than to the email address of the person that made the order.
I can get the email address by using the order ID as it's assigned as a meta data to it, but I do not know how to override where the follow up email address is sent to.
Looking through the Follow Up Emails' API I can see a few hooks that allow me to get the email by ID for example:
$fue_api->get_email( 2011 )
There is another endpoint that seems to be for updating the email:
/**
* Update a follow-up email
* @param integer $email_id
* @param array $data
* @return mixed|json string
*/
public function update_email( $email_id, $data = array() ) {
return $this->_make_api_call( 'emails/' . $email_id, $data, 'POST' );
}
But I am not sure how to change the recipient's email address to the one from the variable?, because:
1) The email of the recipient is only available once an order is made
2) I need to update the email before it's sent and for it to only be sent on order
I don't know how to link these two things together.
I think I need to hook somehow into an event that controls sending emails after an order is made, get the ID of the email I want to modify, and change it's recipient to the one from the order meta data before it's added to the queue.
Any help is greatly appreciated!