반응형
wooCommerce - 기능에서 새 주문/고객 송장 이메일 보내기php 파일
기능을 통해 신규 주문 메일과 고객 송장 메일을 보내려고 합니다.php 파일.
이메일로 보낼 주문 완료 개체를 어떻게 발화합니까?
저는 두 가지 다른 종류의 코드를 시도하고 있습니다.
add_action('woocommerce_payment_complete', 'my_custom_checkout_field_looking');
function my_custom_checkout_field_looking( $order_id ) {
$order = new WC_Order( $order_id );
// first type of Code. Send Email but did not send complete order object.
$mailer = WC()->mailer();
$subject = 'New Order Email # ' . $order_id;
$mailer->send( 'example@gmail.com', $subject, $mailer->wrap_message( $subject, $order ), '', '' );
// Second type of Code. Do not send email and doing nothing
global $woocommerce;
$mailer2 = $woocommerce->mailer();
// Email customer with order-processing receipt
$email = $mailer2->emails['WC_Email_Customer_Invoice'];
$email->trigger( $order );
// Email admin with new order email
$email = $mailer2->emails['WC_Email_New_Order'];
$email->trigger( $order );
}
그런 종류의 코드가 필요할 것 같습니다.
add_action('woocommerce_thankyou', 'my_custom_new_order_email');
function my_custom_new_order_email( $order_id ) {
$order = new WC_Order( $order_id );
$billing_address = $order->get_formatted_billing_address(); // for printing or displaying on web page
$shipping_address = $order->get_formatted_shipping_address();
$email = $order->billing_email;
$name = $order->billing_first_name.' '.$order->billing_last_name;
$billing_phone = $order->billing_phone;
$date = date('M d, Y');
$data = '';
$data .= "<table border='0' cellpadding='0' cellspacing='0' width='600'><tbody><tr>
<td valign='top' style='background-color:#fdfdfd'>
<table border='0' cellpadding='20' cellspacing='0' width='100%'>
<tbody>
<tr>
<td valign='top' style='padding:48px'>
<div style='color:#737373;font-family:"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;font-size:14px;line-height:150%;text-align:left'>
<span>
<p style='margin:0 0 16px'>
You have received an order from $name. The order is as follows:
</p>
</span>
<h2 style='color:#557da1;display:block;font-family:"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;font-size:18px;font-weight:bold;line-height:130%;margin:16px 0 8px;text-align:left'>
Order # $order_id ( $date )
</h2>
<div>
<div>";
if( sizeof( $order->get_items() ) > 0 ) {
$data .= "<table cellspacing='0' cellpadding='6' style='width:100%;border:1px solid #eee' border='1'>
<thead>
<tr>
<th scope='col' style='text-align:left;border:1px solid #eee;padding:12px'>
Product
</th>
<th scope='col' style='text-align:left;border:1px solid #eee;padding:12px'>
Quantity
</th>
<th scope='col' style='text-align:left;border:1px solid #eee;padding:12px'>
Price
</th>
</tr>
</thead>
<tbody>";
$data .= $order->email_order_items_table( false, true );
$data .= "</tbody><tfoot>";
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
$label = $total['label'];
$value = $total['value'];
$data .= "<tr>
<th scope='row' colspan='2' style='text-align:left; border: 1px solid #eee;'>$label</th>
<td style='text-align:left; border: 1px solid #eee;'>$value</td>
</tr>";
}
}
$data .= "</tfoot></table>";
}
$data .=
"<span>
<h2 style='color:#557da1;display:block;font-family:"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;font-size:18px;font-weight:bold;line-height:130%;margin:16px 0 8px;text-align:left'>
Customer details
</h2>
<p style='margin:0 0 16px'>
<strong>Email:</strong>
<a href='mailto:' target='_blank'>
$email
</a>
</p>
<p style='margin:0 0 16px'>
<strong>Tel:</strong>
$billing_phone
</p>
<table cellspacing='0' cellpadding='0' style='width:100%;vertical-align:top' border='0'>
<tbody>
<tr>
<td valign='top' width='50%' style='padding:12px'>
<h3 style='color:#557da1;display:block;font-family:"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;font-size:16px;font-weight:bold;line-height:130%;margin:16px 0 8px;text-align:left'>Billing address</h3>
<p style='margin:0 0 16px'> $billing_address </p>
</td>
<td valign='top' width='50%' style='padding:12px'>
<h3 style='color:#557da1;display:block;font-family:"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;font-size:16px;font-weight:bold;line-height:130%;margin:16px 0 8px;text-align:left'>Shipping address</h3>
<p style='margin:0 0 16px'> $shipping_address </p>
</td>
</tr>
</tbody>
</table>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>";
$mailer = WC()->mailer();
$subject = 'New Customer Order';
$mailer->send( 'abc@example.com,def@example.com', $subject, $mailer->wrap_message( $subject, $data ), '', '' );
}
그것이 당신에게 효과가 있기를 바랍니다.
감사해요.
언급URL : https://stackoverflow.com/questions/38005916/woocommerce-send-new-order-customer-invoice-email-from-functions-php-file
반응형
'prosource' 카테고리의 다른 글
jQuery의 getJSON() 메서드로 요청 헤더를 전달하려면 어떻게 해야 합니까? (0) | 2023.10.25 |
---|---|
하위 폴더의 다른 워드프레스 설치 (0) | 2023.10.20 |
MariaDB 10.2 json insert가 PHP에서 유효하지 않음 (0) | 2023.10.20 |
C에서 구조물의 const를 초기화하는 방법(malloc 포함) (0) | 2023.10.20 |
리소스를 로드하지 못했습니다. net::ERR_CONTENT_LENGTH_MISMATCH (0) | 2023.10.20 |