WC_Post_Data::process_product_file_download_paths PHP Method

process_product_file_download_paths() public static method

Update changed downloads.
public static process_product_file_download_paths ( integer $product_id, integer $variation_id, array $downloads )
$product_id integer product identifier
$variation_id integer optional product variation identifier
$downloads array newly set files
    public static function process_product_file_download_paths($product_id, $variation_id, $downloads)
    {
        if ($variation_id) {
            $product_id = $variation_id;
        }
        $product = wc_get_product($product_id);
        $data_store = WC_Data_Store::load('customer-download');
        if ($downloads) {
            foreach ($downloads as $download) {
                $new_hash = md5($download->get_file());
                if ($download->get_previous_hash() && $download->get_previous_hash() !== $new_hash) {
                    // Update permissions.
                    $data_store->update_download_id($product_id, $download->get_previous_hash(), $new_hash);
                }
            }
        }
    }

Usage Example

 /**
  * Grant downloadable file access to any newly added files on any existing.
  * orders for this product that have previously been granted downloadable file access.
  *
  * @param int $product_id product identifier
  * @param int $variation_id optional product variation identifier
  * @param array $downloadable_files newly set files
  * @deprecated and moved to post-data class.
  */
 public function process_product_file_download_paths($product_id, $variation_id, $downloadable_files)
 {
     WC_Post_Data::process_product_file_download_paths($product_id, $variation_id, $downloadable_files);
 }