在WooCommerce中,我有一个自定义片段,可以将消息添加到我的新订单管理员电子邮件中。它告诉我什么时候一个客户是回头客,以及他们以前下了多少订单。但是,只有当客户拥有注册帐户时才有效。这不适用于任何作为客人退房的人。我如何调整此代码,使其基于账单电子邮件而不是user_id?
function action_woocommerce_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
// Target specific email notification
if ( $email->id == 'new_order' ) {
// Get email
$customer_email = $order->get_billing_email();
// NOT empty
if ( ! empty ( $customer_email ) ) {
// Get orders from customer by email and statuses
$orders_by_customer_email = wc_get_orders( array(
'customer' => $customer_email,
'status' => array( 'wc-on-hold','wc-processing','wc-completed' ),
'limit' => -1,
'return' => 'ids'
));
// When new customer
if ( count( $orders_by_customer_email ) == 1 ) {
$customer = __( 'new', 'woocommerce' );
} else {
$customer = __( 'returning', 'woocommerce' );
}
// Output
echo '<p style="color:red;font-size:14px;">' . sprintf( __( 'Customer: %s, number of purchases: %d', 'woocommerce' ), $customer, count( $orders_by_customer_email ) ) . '</p>';
}
} } add_action( 'woocommerce_email_order_details', 'action_woocommerce_email_order_details', 10, 4 );
1条答案
按热度按时间wj8zmpe11#
支持以下字段查询
billing_first_name, billing_last_name, billing_company, billing_address_1, billing_address_2, billing_city, billing_state, billing_postcode, billing_country, billing_email, billing_phone, shipping_first_name, shipping_last_name, shipping_company, shipping_address_1, shipping_address_2, shipping_city, shipping_state, shipping_postcode, shipping_country, customer_ip_address