Customer report functions need tweaking
-
I found what I think is a design flaw in some of the WooCommerce functions, as well as the Customer List report.
wc_get_customer_total_spent() and wc_get_customer_order_count() retrieve orders based on ‘_customer_user’ meta key. Likewise, the ‘Last Order’ column in the Customer List. However, I think this is insufficient. With one client I found that a few previous customers were not logged in, but used their account email for some orders, so the total spent, order count, and last order were off. I created a new report with modified logic, and it looks like I just need the following tweak:
Instead of
'meta_query' => array( array( 'key' => '_customer_user', 'value' => $user->ID ) ),
in the order queries, have
'meta_query' => array( 'relation' => 'OR', array( 'key' => '_customer_user', 'value' => $user->ID ), array( 'key' => '_billing_email', 'value' => $user->user_email ) ),
(In wc_get_customer_total_spent() and wc_get_customer_order_count(), you’d need to load the user from the user ID to get its email).
- The topic ‘Customer report functions need tweaking’ is closed to new replies.