Automattic\WooCommerce\Internal
DownloadPermissionsAdjuster::get_download_files_and_permissions
Get the existing downloadable files and download permissions for a given product. The returned value is an array with two keys:
- download_ids_by_file_url: an associative array of file url => download_id.
- permission_data_by_file_order_user: an associative array where key is "file_url:customer_id:order_id" and value is the full permission data set.
Method of the class: DownloadPermissionsAdjuster{}
No Hooks.
Returns
Array[]. Information about the downloadable files and permissions for the product.
Usage
// private - for code of main (parent) class only $result = $this->get_download_files_and_permissions( $product );
- $product(WC_Product) (required)
- The product to get the downloadable files and permissions for.
DownloadPermissionsAdjuster::get_download_files_and_permissions() DownloadPermissionsAdjuster::get download files and permissions code WC 10.4.3
private function get_download_files_and_permissions( \WC_Product $product ) {
$result = array(
'permission_data_by_file_order_user' => array(),
'download_ids_by_file_url' => array(),
);
$downloads = $product->get_downloads();
foreach ( $downloads as $download ) {
$result['download_ids_by_file_url'][ $download->get_file() ] = $download->get_id();
}
$permissions = $this->downloads_data_store->get_downloads( array( 'product_id' => $product->get_id() ) );
foreach ( $permissions as $permission ) {
$permission_data = (array) $permission->data;
if ( array_key_exists( $permission_data['download_id'], $downloads ) ) {
$file = $downloads[ $permission_data['download_id'] ]->get_file();
$data = array(
'file' => $file,
'data' => (array) $permission->data,
);
$result['permission_data_by_file_order_user'][ "{$file}:{$permission_data['user_id']}:{$permission_data['order_id']}" ] = $data;
}
}
return $result;
}