WooCommerce電子郵件通知相關訂單。
在woocommerce_email_after_order_table
鉤子中,您將Order對象作爲鉤住自定義函數中的參數,並且還有$email
對象。
隨着該$order
對象,你可以得到user ID
這樣:
$user_id = $user_id = $order->get_user_id();
從$email
對象,你可以針對新訂單的電子郵件通知。
所以工作代碼將是:
add_action('woocommerce_email_after_order_table', 'customer_order_count', 10, 4);
function customer_order_count($order, $sent_to_admin, $plain_text, $email){
if ($order->get_user_id() > 0){
// Targetting new orders (that will be sent to customer and to shop manager)
if ('new_order' == $email->id){
// Getting the user ID
$user_id = $order->get_user_id();
// Get the user order count
$order_count = wc_get_customer_order_count($user_id);
// Display the user order count
echo '<p>Customer order count: '.$order_count.'</p>';
}
}
}
您還可以使用,而不是woocommerce_email_before_order_table
鉤例如...
代碼放在您的活動子主題的function.php文件(或主題)或任何插件文件。
此代碼已經過測試並可正常工作。
這太好了,謝謝!希望我會早點提問。 :-P – protohominid