add_action( 'woocommerce_checkout_order_processed', 'thrd_party_mails', 1, 1 );
function thrd_party_mails( $order_id ){
$order = new WC_Order( $order_id );
if (isset($order) && !empty($order)) {
$items = $order->get_items();
$admin_email = get_option( 'admin_email' );
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product_variation_id = $item->get_variation_id();
$is_3rd_party = get_field( "is_3rd_party", $product_id );
if (isset($is_3rd_party) && $is_3rd_party=='yes') {
$th_party_email = get_field( "3rd_party_email", $product_id );
$is_th_party_mail_subject = get_field( "is_3rd_party_mail_subject", $product_id );
$th_party_content = get_field( "3rd_party_content", $product_id );
$th_party_bottom_content = get_field( "3rd_party_bottom_content", $product_id );
$th_party_admin_mail = get_field( "3rd_party_admin_mail", $product_id );
if (isset($th_party_admin_mail) && $th_party_admin_mail==1) {
$thtomail =$admin_email.' ,'.$th_party_email;
}else {
$thtomail = $th_party_email;
}
$ordrfirstname = $order->get_billing_first_name();
$ordrlastname = $order->get_billing_last_name();
$ordremail = $order->get_billing_email();
$headers[] = 'From: PM Champion <info@pmchampion.com>';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$thcontent="<table style='text-align: left;''>
<tr> <th style=' padding-bottom: 15px;' colspan='2'>New Order Mail #".$order_id."</th></tr>
<tr><td style=' padding-bottom: 15px;' colspan='2'>".$th_party_content."</td></tr>
<tr> <th>Client Info:</th> </tr>
<tr><th>First Name</th> <td>".$ordrfirstname."</td> </tr>
<tr><th>Last Name</th> <td>".$ordrlastname."</td> </tr>
<tr><th>E-Mail: </th> <td>".$ordremail."</td> </tr>
<tr><th style=' padding-bottom: 15px;'>Order iD </th> <td style=' padding-bottom: 15px;'>#".$order_id."</td> </tr>
<tr><td colspan='2'>".$th_party_bottom_content."</td></tr>
</table>";
wp_mail( $thtomail, $is_th_party_mail_subject, $thcontent, $headers );
}
}
}
}
function thrd_party_mails( $order_id ){
$order = new WC_Order( $order_id );
if (isset($order) && !empty($order)) {
$items = $order->get_items();
$admin_email = get_option( 'admin_email' );
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product_variation_id = $item->get_variation_id();
$is_3rd_party = get_field( "is_3rd_party", $product_id );
if (isset($is_3rd_party) && $is_3rd_party=='yes') {
$th_party_email = get_field( "3rd_party_email", $product_id );
$is_th_party_mail_subject = get_field( "is_3rd_party_mail_subject", $product_id );
$th_party_content = get_field( "3rd_party_content", $product_id );
$th_party_bottom_content = get_field( "3rd_party_bottom_content", $product_id );
$th_party_admin_mail = get_field( "3rd_party_admin_mail", $product_id );
if (isset($th_party_admin_mail) && $th_party_admin_mail==1) {
$thtomail =$admin_email.' ,'.$th_party_email;
}else {
$thtomail = $th_party_email;
}
$ordrfirstname = $order->get_billing_first_name();
$ordrlastname = $order->get_billing_last_name();
$ordremail = $order->get_billing_email();
$headers[] = 'From: PM Champion <info@pmchampion.com>';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$thcontent="<table style='text-align: left;''>
<tr> <th style=' padding-bottom: 15px;' colspan='2'>New Order Mail #".$order_id."</th></tr>
<tr><td style=' padding-bottom: 15px;' colspan='2'>".$th_party_content."</td></tr>
<tr> <th>Client Info:</th> </tr>
<tr><th>First Name</th> <td>".$ordrfirstname."</td> </tr>
<tr><th>Last Name</th> <td>".$ordrlastname."</td> </tr>
<tr><th>E-Mail: </th> <td>".$ordremail."</td> </tr>
<tr><th style=' padding-bottom: 15px;'>Order iD </th> <td style=' padding-bottom: 15px;'>#".$order_id."</td> </tr>
<tr><td colspan='2'>".$th_party_bottom_content."</td></tr>
</table>";
wp_mail( $thtomail, $is_th_party_mail_subject, $thcontent, $headers );
}
}
}
}
Comments
Post a Comment