add_action ('woocommerce_email_customer_details', 'custom_email_customer_details', 15, 4);
function custom_email_customer_details( $order, $sent_to_admin, $plain_text, $email ){
// Only for "New Order" email notification
if ( 'new_order' != $email->id ) return;
// Only "Flat Rate" Shipping Method
if ( $order->has_shipping_method('flat_rate') ){
$order_id = $order->get_id(); // The Order ID
// Test output
echo "<p>Message: The Order ID is $order_id</p>";
echo '<p>Custom field: '. get_post_meta( $order_id, '_recorded_sales', true ) .'</p>';
}
}
1 回答
您可以使用挂钩在任何此挂钩中的自定义函数(调整挂钩优先级):
woocommerce_email_order_details
woocommerce_email_order_meta
woocommerce_email_customer_details
这是一个钩子代码的例子(而不是覆盖模板):
这里的挂钩优先级是15,所以它是在客户详细信息之后 .
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
此代码经过测试和运行 .