WordPress at Your Fingertips
function is not described

WC_Privacy_Exporters::download_data_exporter() public WC 3.4.0

Finds and exports customer download logs by email address.

{} It's a method of the class: WC_Privacy_Exporters{}

No Hooks.

Return

Array. An array of personal data in name value pairs

Usage

$result = WC_Privacy_Exporters::download_data_exporter( $email_address, $page );
$email_address(string) (required)
The user email address.
$page(int) (required)
Page.

Changelog

Since 3.4.0 Introduced.

Code of WC_Privacy_Exporters::download_data_exporter() WC 5.8.0

public static function download_data_exporter( $email_address, $page ) {
	$done            = true;
	$page            = (int) $page;
	$user            = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
	$data_to_export  = array();
	$downloads_query = array(
		'limit' => 10,
		'page'  => $page,
	);

	if ( $user instanceof WP_User ) {
		$downloads_query['user_id'] = (int) $user->ID;
	} else {
		$downloads_query['user_email'] = $email_address;
	}

	$customer_download_data_store     = WC_Data_Store::load( 'customer-download' );
	$customer_download_log_data_store = WC_Data_Store::load( 'customer-download-log' );
	$downloads                        = $customer_download_data_store->get_downloads( $downloads_query );

	if ( 0 < count( $downloads ) ) {
		foreach ( $downloads as $download ) {
			$data_to_export[] = array(
				'group_id'          => 'woocommerce_downloads',
				/* translators: This is the headline for a list of downloads purchased from the store for a given user. */
				'group_label'       => __( 'Purchased Downloads', 'woocommerce' ),
				'group_description' => __( 'User&#8217;s WooCommerce purchased downloads data.', 'woocommerce' ),
				'item_id'           => 'download-' . $download->get_id(),
				'data'              => self::get_download_personal_data( $download ),
			);

			$download_logs = $customer_download_log_data_store->get_download_logs_for_permission( $download->get_id() );

			foreach ( $download_logs as $download_log ) {
				$data_to_export[] = array(
					'group_id'          => 'woocommerce_download_logs',
					/* translators: This is the headline for a list of access logs for downloads purchased from the store for a given user. */
					'group_label'       => __( 'Access to Purchased Downloads', 'woocommerce' ),
					'group_description' => __( 'User&#8217;s WooCommerce access to purchased downloads data.', 'woocommerce' ),
					'item_id'           => 'download-log-' . $download_log->get_id(),
					'data'              => array(
						array(
							'name'  => __( 'Download ID', 'woocommerce' ),
							'value' => $download_log->get_permission_id(),
						),
						array(
							'name'  => __( 'Timestamp', 'woocommerce' ),
							'value' => $download_log->get_timestamp(),
						),
						array(
							'name'  => __( 'IP Address', 'woocommerce' ),
							'value' => $download_log->get_user_ip_address(),
						),
					),
				);
			}
		}
		$done = 10 > count( $downloads );
	}

	return array(
		'data' => $data_to_export,
		'done' => $done,
	);
}