blic static function schedule_anonymize( $order ) { if ( is_a( $order, 'WC_Order' ) ) { // Postpone until any pending updates are completed. self::schedule_action( 'anonymize', array( $order->get_id() ) ); } } /** * Schedule an action to delete a single User. * * @param int $user_id User ID. * @return void */ public static function schedule_user_delete( $user_id ) { if ( (int) $user_id > 0 ) { // Postpone until any pending updates are completed. self::schedule_action( 'delete_user', array( $user_id ) ); } } /** * Imports a single customer. * * @param int $user_id User ID. * @return void */ public static function import( $user_id ) { CustomersDataStore::update_registered_customer( $user_id ); } /** * Delete a batch of customers. * * @param int $batch_size Number of items to delete. * @return void */ public static function delete( $batch_size ) { global $wpdb; $customer_ids = $wpdb->get_col( $wpdb->prepare( "SELECT customer_id FROM {$wpdb->prefix}wc_customer_lookup ORDER BY customer_id ASC LIMIT %d", $batch_size ) ); foreach ( $customer_ids as $customer_id ) { CustomersDataStore::delete_customer( $customer_id ); } } /** * Anonymize the customer data for a single order. * * @param int $order_id Order id. * @return void */ public static function anonymize( $order_id ) { global $wpdb; $customer_id = $wpdb->get_var( $wpdb->prepare( "SELECT customer_id FROM {$wpdb->prefix}wc_order_stats WHERE order_id = %d", $order_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, 'deleted@site.invalid', $deleted_text, $deleted_text, $deleted_text, $customer_id, ) ) ); // If the customer row was anonymized, flush the cache. if ( $updated ) { ReportsCache::invalidate(); } } /** * Delete the customer data for a single user. * * @param int $user_id User ID. * @return void */ public static function delete_user( $user_id ) { CustomersDataStore::delete_customer_by_user_id( $user_id ); } }