WC_Product_Data_Store_CPT::read_downloads PHP Method

read_downloads() protected method

Read downloads from post meta.
Since: 2.7.0
protected read_downloads ( &$product )
    protected function read_downloads(&$product)
    {
        $meta_values = array_filter((array) maybe_unserialize(get_post_meta($product->get_id(), '_downloadable_files', true)));
        if ($meta_values) {
            $downloads = array();
            foreach ($meta_values as $key => $value) {
                $download = new WC_Product_Download();
                $download->set_id($key);
                $download->set_name($value['name'] ? $value['name'] : wc_get_filename_from_url($value['file']));
                $download->set_file(apply_filters('woocommerce_file_download_path', $value['file'], $product, $key));
                $downloads[] = $download;
            }
            $product->set_downloads($downloads);
        }
    }