Automattic\WooCommerce\Admin\API\Reports\Customers
DataStore::anonymize_customer
Anonymize the customer data for a single order.
Method of the class: DataStore{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = DataStore::anonymize_customer( $order );
- $order(int|WC_Order) (required)
- Order instance or ID.
DataStore::anonymize_customer() DataStore::anonymize customer code WC 10.3.6
public static function anonymize_customer( $order ) {
global $wpdb;
if ( ! is_object( $order ) ) {
$order = wc_get_order( absint( $order ) );
}
$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;
}
// Long form query because $wpdb->update rejects [deleted].
$deleted_text = __( '[deleted]', 'woocommerce' );
$updated = $wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}wc_customer_lookup
SET
user_id = NULL,
username = %s,
first_name = %s,
last_name = %s,
email = %s,
country = '',
postcode = %s,
city = %s,
state = %s
WHERE
customer_id = %d",
array(
$deleted_text,
$deleted_text,
$deleted_text,
'[email protected]',
$deleted_text,
$deleted_text,
$deleted_text,
$customer_id,
)
)
);
// If the customer row was anonymized, flush the cache.
if ( $updated ) {
ReportsCache::invalidate();
}
}