I have a checkout form with a custom field.
I would like to add an extra recipient to an order email based on the value in the custom field. The custom field is currently a drop down menu with only 3 options.
Below is the code I was able to piece together with some googling however this does not appear to work.
function sv_conditional_email_recipient( $recipient, $order ) {
$custom_field = get_post_meta($orderid, 'custom_field', true);
if ($custom_field == "Value 1")
{
$recipient .= ', email1@gmail.com';
}
elseif ($custom_field == "Value 2")
{
$recipient .= ', email2@gmail.com';
}
elseif ($custom_field == "Value 3")
{
$recipient .= ', email3@gmail.com';
}
return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
Any help is appreciated.
Thanks.