当创建默认WooCommerce新订单时,我正在try 将额外的邮箱发送到所需的邮箱地址.并希望默认的新订单仍然有效.一切都很好,也收到了邮件.
但对于定制邮箱,我没有得到订单细节-我只想要没有价格,客户笔记和订单编号和日期的项目细节.
以下是代码:
add_action( 'woocommerce_new_order', 'send_custom_order_email', 10, 1 );
function send_custom_order_email( $order_id ) {
// Get the order object
$order = wc_get_order( $order_id );
// Prepare order details without prices
$order_details = '';
foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$product_name = $product ? $product->get_formatted_name() : $item['name'];
$item_quantity = $item->get_quantity();
$order_details .= "Product: $product_name - Quantity: $item_quantity\n";
}
// Include the desired details in the email content
$details_to_include = "Order Date: {$order->get_date_created()->format( 'F j, Y' )}\nOrder Number: {$order->get_order_number()}\n\nOrder Details:\n$order_details\nCustomer Note: {$order->get_customer_note()}\n";
// Email subject and content
$email_subject = 'New Order: ' . $order->get_order_number();
$email_content = $details_to_include;
// Email recipient
$desired_email = 'desired@email.com'; // Replace with the desired email address
// Send the desired email with the order details
wp_mail( $desired_email, $email_subject, $email_content );
}