Skip to main content

How to send custom email template on buy specific product in woocommerce?

Send custom email template on buy specific product in woocommerce



add_action( 'woocommerce_thankyou', 'wpcodekit_check_order_product_id' );

function wpcodekit_check_order_product_id( $order_id ){

$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
   $product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
   if($product_id === 6112) {
 
$customername = $order->get_billing_first_name() .' '.$order->get_billing_last_name();
$message = file_get_contents(WP_CONTENT_DIR . '/themes/twentynineteen-child/emails/premiumsupport.html');
$message = str_replace("{customeremail}",$customername,$message);
$toadmin = $order->get_billing_email();
$quotename = "Let Us Structure Your Partnership";
$headers = 'From: "' . $quotename . '" <no-reply@brrrrinvest.com>' . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

wp_mail( $toadmin, $quotename, $message, $headers );
}

if(($product_id === 2750)||($product_id === 2749)) {
 
$customername = $order->get_billing_first_name() .' '.$order->get_billing_last_name();
$message = file_get_contents(WP_CONTENT_DIR . '/themes/twentynineteen-child/emails/emailconsult.html');
$message = str_replace("{customeremail}",$customername,$message);
$toadmin = $order->get_billing_email();
$quotename = "Let Us Structure Your Partnership";
$headers = 'From: "' . $quotename . '" <no-reply@brrrrinvest.com>' . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

wp_mail( $toadmin, $quotename, $message, $headers );
}
}
}

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...