public static function grant_access_to_download()
{
check_ajax_referer('grant-access', 'security');
if (!current_user_can('edit_shop_orders')) {
die(-1);
}
global $wpdb;
$wpdb->hide_errors();
$order_id = intval($_POST['order_id']);
$product_ids = $_POST['product_ids'];
$loop = intval($_POST['loop']);
$file_counter = 0;
$order = wc_get_order($order_id);
if (!is_array($product_ids)) {
$product_ids = array($product_ids);
}
foreach ($product_ids as $product_id) {
$product = wc_get_product($product_id);
$files = $product->get_downloads();
if (!$order->get_billing_email()) {
die;
}
if (!empty($files)) {
foreach ($files as $download_id => $file) {
if ($inserted_id = wc_downloadable_file_permission($download_id, $product_id, $order)) {
$download = new WC_Customer_Download($inserted_id);
$loop++;
$file_counter++;
if ($file->get_name()) {
$file_count = $file->get_name();
} else {
$file_count = sprintf(__('File %d', 'woocommerce'), $file_counter);
}
include 'admin/meta-boxes/views/html-order-download-permission.php';
}
}
}
}
die;
}