Automattic\WooCommerce\Admin\API\Reports\Customers

DataStore::anonymize_customer()public staticWC 1.0

Anonymize the customer data for a single order.

Метод класса: DataStore{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = DataStore::anonymize_customer( $order_id );
$order_id(int) (обязательный)
Order id.

Код DataStore::anonymize_customer() WC 9.2.3

public static function anonymize_customer( $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();
	}
}