Prevent duplicate customer imports (https://github.com/woocommerce/woocommerce-admin/pull/2428)
* Get customer ID from existing order ID if present * Use get_report_customer_id method in order for both orders and refunds
This commit is contained in:
parent
57416a2bdb
commit
ee81663f99
|
@ -442,9 +442,21 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
|
|||
return false;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$user_id = $order->get_customer_id();
|
||||
|
||||
if ( 0 === $user_id ) {
|
||||
$customer_id = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT customer_id FROM {$wpdb->prefix}wc_order_stats WHERE order_id = %d",
|
||||
$order->get_id()
|
||||
)
|
||||
);
|
||||
|
||||
if ( $customer_id ) {
|
||||
return $customer_id;
|
||||
}
|
||||
|
||||
$email = $order->get_billing_email( 'edit' );
|
||||
|
||||
if ( $email ) {
|
||||
|
|
|
@ -436,13 +436,11 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
|
|||
);
|
||||
|
||||
if ( 'shop_order_refund' === $order->get_type() ) {
|
||||
$parent_order = wc_get_order( $order->get_parent_id() );
|
||||
$data['customer_id'] = WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( $parent_order );
|
||||
$data['parent_id'] = $parent_order->get_id();
|
||||
$format[] = '%d';
|
||||
$parent_order = wc_get_order( $order->get_parent_id() );
|
||||
$data['parent_id'] = $parent_order->get_id();
|
||||
$format[] = '%d';
|
||||
} else {
|
||||
$data['returning_customer'] = self::is_returning_customer( $order );
|
||||
$data['customer_id'] = WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( $order );
|
||||
}
|
||||
|
||||
// Update or add the information to the DB.
|
||||
|
|
Loading…
Reference in New Issue