function ck_edd_user_download_button($purchase_form, $args)
{
    global $edd_options;
    if (!is_user_logged_in()) {
        return $purchase_form;
    }
    $download_id = (string) $args['download_id'];
    $current_user_id = get_current_user_id();
    // If the user has purchased this item, itterate through their purchases to get the specific
    // purchase data and pull out the key and email associated with it. This is necessary for the
    // generation of the download link
    if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) {
        $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete');
        foreach ($user_purchases as $purchase) {
            $cart_items = edd_get_payment_meta_cart_details($purchase->ID);
            $item_ids = wp_list_pluck($cart_items, 'id');
            if (in_array($download_id, $item_ids)) {
                $email = edd_get_payment_user_email($purchase->ID);
                $payment_key = edd_get_payment_key($purchase->ID);
            }
        }
        $download_ids = array();
        if (edd_is_bundled_product($download_id)) {
            $download_ids = edd_get_bundled_products($download_id);
        } else {
            $download_ids[] = $download_id;
        }
        // Setup the style and colors associated with the settings
        $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button';
        $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
        $new_purchase_form = '';
        foreach ($download_ids as $item) {
            // Attempt to get the file data associated with this download
            $download_data = edd_get_download_files($item, null);
            if ($download_data) {
                foreach ($download_data as $filekey => $file) {
                    // Generate the file URL and then make a link to it
                    $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $item, null);
                    $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a>&nbsp;';
                }
            }
            // As long as we ended up with links to show, use them.
            if (!empty($new_purchase_form)) {
                $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form;
            }
        }
    }
    return $purchase_form;
}
/**
 * Email Template Tags
 *
 * @access      private
 * @since       1.0 
 * @return      string
*/
function edd_email_templage_tags($message, $payment_data, $payment_id)
{
    $user_info = maybe_unserialize($payment_data['user_info']);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name'])) {
        $name = $user_info['first_name'];
    } else {
        $name = $user_info['email'];
    }
    $download_list = '<ul>';
    $downloads = maybe_unserialize($payment_data['downloads']);
    if ($downloads) {
        foreach (maybe_unserialize($payment_data['downloads']) as $download) {
            $id = isset($payment_data['cart_details']) ? $download['id'] : $download;
            $download_list .= '<li>' . get_the_title($id) . '<br/>';
            $download_list .= '<ul>';
            $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
            $files = edd_get_download_files($id, $price_id);
            if ($files) {
                foreach ($files as $filekey => $file) {
                    $download_list .= '<li>';
                    $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $id);
                    $download_list .= '<a href="' . $file_url . '">' . $file['name'] . '</a>';
                    $download_list .= '</li>';
                }
            }
            $download_list .= '</ul></li>';
        }
    }
    $download_list .= '</ul>';
    $price = edd_currency_filter($payment_data['amount']);
    $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true));
    $receipt_id = $payment_data['key'];
    $message = str_replace('{name}', $name, $message);
    $message = str_replace('{download_list}', $download_list, $message);
    $message = str_replace('{date}', date(get_option('date_format'), strtotime($payment_data['date'])), $message);
    $message = str_replace('{sitename}', get_bloginfo('name'), $message);
    $message = str_replace('{price}', $price, $message);
    $message = str_replace('{payment_method}', $gateway, $message);
    $message = str_replace('{receipt_id}', $receipt_id, $message);
    $message = apply_filters('edd_email_template_tags', $message, $payment_data);
    return $message;
}
/**
 * Gets the download links for each item purchased
 *
 * @since 1.1.5
 * @param int $payment_id The ID of the payment to retrieve download links for
 * @return string
 */
function edd_get_purchase_download_links($payment_id = 0)
{
    $downloads = edd_get_payment_meta_cart_details($payment_id, true);
    $payment_key = edd_get_payment_key($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    $links = '<ul class="edd_download_links">';
    foreach ($downloads as $download) {
        $links .= '<li>';
        $links .= '<h3 class="edd_download_link_title">' . esc_html(get_the_title($download['id'])) . '</h3>';
        $price_id = isset($download['options']) && isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
        $files = edd_get_download_files($download['id'], $price_id);
        if (is_array($files)) {
            foreach ($files as $filekey => $file) {
                $links .= '<div class="edd_download_link_file">';
                $links .= '<a href="' . esc_url(edd_get_download_file_url($payment_key, $email, $filekey, $download['id'], $price_id)) . '">';
                if (isset($file['name'])) {
                    $links .= esc_html($file['name']);
                } else {
                    $links .= esc_html($file['file']);
                }
                $links .= '</a>';
                $links .= '</div>';
            }
        }
        $links .= '</li>';
    }
    $links .= '</ul>';
    return $links;
}
 setup_postdata($post);
 $downloads = edd_get_payment_meta_downloads($post->ID);
 $purchase_data = edd_get_payment_meta($post->ID);
 if ($downloads) {
     foreach ($downloads as $download) {
         echo '<tr class="edd_download_history_row">';
         $id = isset($purchase_data['cart_details']) ? $download['id'] : $download;
         $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
         $download_files = edd_get_download_files($id, $price_id);
         do_action('edd_download_history_row_start', $post->ID, $id);
         echo '<td class="edd_download_download_name">' . get_the_title($id) . '</td>';
         if (!edd_no_redownload()) {
             echo '<td class="edd_download_download_files">';
             if ($download_files) {
                 foreach ($download_files as $filekey => $file) {
                     $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $id);
                     echo '<div class="edd_download_file"><a href="' . esc_url($download_url) . '" class="edd_download_file_link">' . esc_html($file['name']) . '</a></div>';
                     do_action('edd_download_history_files', $filekey, $file, $id, $post->ID, $purchase_data);
                 }
             } else {
                 _e('No downloadable files found.', 'edd');
             }
             echo '</td>';
         }
         // end if ! edd_no_redownload()
         do_action('edd_download_history_row_end', $post->ID, $id);
         echo '</tr>';
     }
     // end foreach $downloads
     wp_reset_postdata();
 }
/**
 * Retrieves a new download link for a purchased file
 *
 * @since 2.0
 * @return string
*/
function edd_ajax_generate_file_download_link()
{
    if (!current_user_can('view_shop_reports')) {
        die('-1');
    }
    $payment_id = absint($_POST['payment_id']);
    $download_id = absint($_POST['download_id']);
    $price_id = absint($_POST['price_id']);
    if (empty($payment_id)) {
        die('-2');
    }
    if (empty($download_id)) {
        die('-3');
    }
    $payment_key = edd_get_payment_key($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    $limit = edd_get_file_download_limit($download_id);
    if (!empty($limit)) {
        // Increase the file download limit when generating new links
        edd_set_file_download_limit_override($download_id, $payment_id);
    }
    $files = edd_get_download_files($download_id, $price_id);
    if (!$files) {
        die('-4');
    }
    $file_urls = '';
    foreach ($files as $file_key => $file) {
        $file_urls .= edd_get_download_file_url($payment_key, $email, $file_key, $download_id, $price_id);
        $file_urls .= "\n\n";
    }
    die($file_urls);
}
/**
 * Email template tag: file_urls
 * A plain-text list of download URLs for each download purchased
 *
 * @param int $payment_id
 *
 * @return string $file_urls
 */
function edd_email_tag_file_urls($payment_id)
{
    $payment_data = edd_get_payment_meta($payment_id);
    $file_urls = '';
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    foreach ($cart_items as $item) {
        $price_id = edd_get_cart_item_price_id($item);
        $files = edd_get_download_files($item['id'], $price_id);
        if ($files) {
            foreach ($files as $filekey => $file) {
                $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $item['id'], $price_id);
                $file_urls .= esc_html($file_url) . '<br/>';
            }
        } elseif (edd_is_bundled_product($item['id'])) {
            $bundled_products = apply_filters('edd_email_tag_bundled_products', edd_get_bundled_products($item['id']), $item, $payment_id, 'file_urls');
            foreach ($bundled_products as $bundle_item) {
                $files = edd_get_download_files($bundle_item);
                foreach ($files as $filekey => $file) {
                    $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $bundle_item, $price_id);
                    $file_urls .= esc_html($file_url) . '<br/>';
                }
            }
        }
    }
    return $file_urls;
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     global $user_ID, $edd_options;
     if (is_user_logged_in()) {
         $purchases = edd_get_users_purchases($user_ID);
         if ($purchases) {
             echo $before_widget;
             if ($title) {
                 echo $before_title . $title . $after_title;
             }
             foreach ($purchases as $purchase) {
                 $purchase_data = edd_get_payment_meta($purchase->ID);
                 $downloads = edd_get_payment_meta_downloads($purchase->ID);
                 if ($downloads) {
                     foreach ($downloads as $download) {
                         $id = isset($purchase_data['cart_details']) ? $download['id'] : $download;
                         $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
                         $download_files = edd_get_download_files($id, $price_id);
                         echo '<div class="edd-purchased-widget-purchase edd-purchased-widget-purchase-' . $purchase->ID . '" id="edd-purchased-widget-purchase-' . $id . '">';
                         echo '<div class="edd-purchased-widget-purchase-name">' . get_the_title($id) . '</div>';
                         echo '<ul class="edd-purchased-widget-file-list">';
                         if (!edd_no_redownload()) {
                             if ($download_files) {
                                 foreach ($download_files as $filekey => $file) {
                                     $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $id, $price_id);
                                     echo '<li class="edd-purchased-widget-file"><a href="' . $download_url . '" class="edd-purchased-widget-file-link">' . $file['name'] . '</a></li>';
                                 }
                             } else {
                                 echo '<li class="edd-purchased-widget-no-file">' . __('No downloadable files found.', 'edd');
                             }
                         }
                         echo '</ul>';
                         echo '</div>';
                     }
                 }
             }
         }
         echo $after_widget;
     }
 }
                do_action('edd_download_history_row_start', $payment->ID, $download['id']);
                ?>
						<td class="edd_download_download_name"><?php 
                echo esc_html($name);
                ?>
</td>

						<?php 
                if (!edd_no_redownload()) {
                    ?>
							<td class="edd_download_download_files">
								<?php 
                    if ('publish' == $payment->post_status) {
                        if ($download_files) {
                            foreach ($download_files as $filekey => $file) {
                                $download_url = edd_get_download_file_url($purchase_data['key'], $email, $filekey, $download['id'], $price_id);
                                ?>

											<div class="edd_download_file">
												<a href="<?php 
                                echo esc_url($download_url);
                                ?>
" class="edd_download_file_link">
													<?php 
                                echo edd_get_file_name($file);
                                ?>
												</a>
											</div>

											<?php 
                                do_action('edd_download_history_files', $filekey, $file, $id, $payment->ID, $purchase_data);
/**
 * Email Template Tags
 *
 * @since 1.0
 *
 * @param string $message Message with the template tags
 * @param array $payment_data Payment Data
 * @param int $payment_id Payment ID
 *
 * @return string $message Fully formatted message
 */
function edd_email_template_tags($message, $payment_data, $payment_id)
{
    global $edd_options;
    $has_tags = strpos($message, '{') !== false;
    if (!$has_tags) {
        return $message;
    }
    $user_info = maybe_unserialize($payment_data['user_info']);
    $fullname = '';
    if (isset($user_info['id']) && $user_info['id'] > 0 && isset($user_info['first_name'])) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_info['first_name'];
        $fullname = $user_info['first_name'] . ' ' . $user_info['last_name'];
        $username = $user_data->user_login;
    } elseif (isset($user_info['first_name'])) {
        $name = $user_info['first_name'];
        $fullname = $user_info['first_name'] . ' ' . $user_info['last_name'];
        $username = $user_info['first_name'];
    } else {
        $name = $user_info['email'];
        $username = $user_info['email'];
    }
    $file_urls = '';
    $download_list = '<ul>';
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    if ($cart_items) {
        $show_names = apply_filters('edd_email_show_names', true);
        foreach ($cart_items as $item) {
            if (edd_use_skus()) {
                $sku = edd_get_download_sku($item['id']);
            }
            $price_id = edd_get_cart_item_price_id($item);
            if ($show_names) {
                $title = get_the_title($item['id']);
                if (!empty($sku)) {
                    $title .= "&nbsp;&ndash;&nbsp;" . __('SKU', 'edd') . ': ' . $sku;
                }
                if ($price_id !== false) {
                    $title .= "&nbsp;&ndash;&nbsp;" . edd_get_price_option_name($item['id'], $price_id);
                }
                $download_list .= '<li>' . apply_filters('edd_email_receipt_download_title', $title, $item['id'], $price_id) . '<br/>';
                $download_list .= '<ul>';
            }
            $files = edd_get_download_files($item['id'], $price_id);
            if ($files) {
                foreach ($files as $filekey => $file) {
                    $download_list .= '<li>';
                    $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $item['id'], $price_id);
                    $download_list .= '<a href="' . esc_url($file_url) . '">' . $file['name'] . '</a>';
                    $download_list .= '</li>';
                    $file_urls .= esc_html($file_url) . '<br/>';
                }
            }
            if ($show_names) {
                $download_list .= '</ul>';
            }
            if ('' != edd_get_product_notes($item['id'])) {
                $download_list .= ' &mdash; <small>' . edd_get_product_notes($item['id']) . '</small>';
            }
            if ($show_names) {
                $download_list .= '</li>';
            }
        }
    }
    $download_list .= '</ul>';
    $subtotal = isset($payment_data['subtotal']) ? $payment_data['subtotal'] : $payment_data['amount'];
    $subtotal = edd_currency_filter(edd_format_amount($subtotal));
    $tax = isset($payment_data['tax']) ? $payment_data['tax'] : 0;
    $tax = edd_currency_filter(edd_format_amount($tax));
    $price = edd_currency_filter(edd_format_amount($payment_data['amount']));
    $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true));
    $receipt_id = $payment_data['key'];
    $message = str_replace('{name}', $name, $message);
    $message = str_replace('{fullname}', $fullname, $message);
    $message = str_replace('{username}', $username, $message);
    $message = str_replace('{download_list}', $download_list, $message);
    $message = str_replace('{file_urls}', $file_urls, $message);
    $message = str_replace('{date}', date_i18n(get_option('date_format'), strtotime($payment_data['date'])), $message);
    $message = str_replace('{sitename}', get_bloginfo('name'), $message);
    $message = str_replace('{subtotal}', $subtotal, $message);
    $message = str_replace('{tax}', $tax, $message);
    $message = str_replace('{price}', $price, $message);
    $message = str_replace('{payment_method}', $gateway, $message);
    $message = str_replace('{receipt_id}', $receipt_id, $message);
    $message = str_replace('{payment_id}', $payment_id, $message);
    $message = str_replace('{receipt_link}', sprintf(__('%1$sView it in your browser.%2$s', 'edd'), '<a href="' . add_query_arg(array('purchase_key' => $receipt_id, 'edd_action' => 'view_receipt'), home_url()) . '">', '</a>'), $message);
    $message = apply_filters('edd_email_template_tags', $message, $payment_data, $payment_id);
    return $message;
}
/**
 * Gets the download links for each item purchased
 *
 * @access      private
 * @since       1.1.5
 * @return      string
*/
function edd_get_purchase_download_links($purchase_data)
{
    if (!is_array($purchase_data['downloads'])) {
        return '<div class="edd-error">' . __('No downloads found', 'edd') . '</div>';
    }
    $links = '<ul class="edd_download_links">';
    foreach ($purchase_data['downloads'] as $download) {
        $links .= '<li>';
        $links .= '<h3 class="edd_download_link_title">' . esc_html(get_the_title($download['id'])) . '</h3>';
        $price_id = isset($download['options']) && isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
        $files = edd_get_download_files($download['id'], $price_id);
        if (is_array($files)) {
            foreach ($files as $filekey => $file) {
                $links .= '<div class="edd_download_link_file">';
                $links .= '<a href="' . esc_url(edd_get_download_file_url($purchase_data['purchase_key'], $purchase_data['user_email'], $filekey, $download['id'])) . '">';
                if (isset($file['name'])) {
                    $links .= esc_html($file['name']);
                } else {
                    $links .= esc_html($file['file']);
                }
                $links .= '</a>';
                $links .= '</div>';
            }
        }
        $links .= '</li>';
    }
    $links .= '</ul>';
    return $links;
}
/**
 * Email Template Tags
 *
 * @param string $message
 * @param array  $payment_data
 * @param int    $payment_id
 *
 * @access private
 * @since 1.0
 * @return string
 */
function edd_email_template_tags($message, $payment_data, $payment_id)
{
    $user_info = maybe_unserialize($payment_data['user_info']);
    $fullname = '';
    if (isset($user_info['id']) && $user_info['id'] > 0 && isset($user_info['first_name'])) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_info['first_name'];
        $fullname = $user_info['first_name'] . ' ' . $user_info['last_name'];
        $username = $user_data->user_login;
    } elseif (isset($user_info['first_name'])) {
        $name = $user_info['first_name'];
        $fullname = $user_info['first_name'] . ' ' . $user_info['last_name'];
        $username = $user_info['first_name'];
    } else {
        $name = $user_info['email'];
        $username = $user_info['email'];
    }
    $file_urls = '';
    $download_list = '<ul>';
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if ($downloads) {
        $show_names = apply_filters('edd_email_show_names', true);
        foreach ($downloads as $download) {
            $id = isset($payment_data['cart_details']) ? $download['id'] : $download;
            if ($show_names) {
                $download_list .= '<li>' . get_the_title($id) . '<br/>';
                $download_list .= '<ul>';
            }
            $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
            $files = edd_get_download_files($id, $price_id);
            if ($files) {
                foreach ($files as $filekey => $file) {
                    $download_list .= '<li>';
                    $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $id);
                    $download_list .= '<a href="' . esc_url($file_url) . '">' . $file['name'] . '</a>';
                    $download_list .= '</li>';
                    $file_urls .= esc_html($file_url) . '<br/>';
                }
            }
            if ($show_names) {
                $download_list .= '</ul>';
            }
            if ('' != edd_get_product_notes($id)) {
                $download_list .= ' &mdash; <small>' . edd_get_product_notes($id) . '</small>';
            }
            if ($show_names) {
                $download_list .= '</li>';
            }
        }
    }
    $download_list .= '</ul>';
    $subtotal = isset($payment_data['subtotal']) ? $payment_data['subtotal'] : $payment_data['amount'];
    $subtotal = edd_currency_filter(edd_format_amount($subtotal));
    $tax = isset($payment_data['tax']) ? $payment_data['tax'] : 0;
    $tax = edd_currency_filter(edd_format_amount($tax));
    $price = edd_currency_filter(edd_format_amount($payment_data['amount']));
    $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true));
    $receipt_id = $payment_data['key'];
    $message = str_replace('{name}', $name, $message);
    $message = str_replace('{fullname}', $fullname, $message);
    $message = str_replace('{username}', $username, $message);
    $message = str_replace('{download_list}', $download_list, $message);
    $message = str_replace('{file_urls}', $file_urls, $message);
    $message = str_replace('{date}', date_i18n(get_option('date_format'), strtotime($payment_data['date'])), $message);
    $message = str_replace('{sitename}', get_bloginfo('name'), $message);
    $message = str_replace('{subtotal}', $subtotal, $message);
    $message = str_replace('{tax}', $tax, $message);
    $message = str_replace('{price}', $price, $message);
    $message = str_replace('{payment_method}', $gateway, $message);
    $message = str_replace('{receipt_id}', $receipt_id, $message);
    $message = apply_filters('edd_email_template_tags', $message, $payment_data, $payment_id);
    return $message;
}
            echo edd_get_product_notes($item['id']);
            ?>
</div>
					<?php 
        }
        ?>

					<?php 
        if (edd_is_payment_complete($payment->ID)) {
            ?>
					<ul>

						<?php 
            if ($download_files && is_array($download_files)) {
                foreach ($download_files as $filekey => $file) {
                    $download_url = edd_get_download_file_url($meta['key'], $meta['email'], $filekey, $item['id'], $price_id);
                    ?>
								<li class="edd_download_file">
									<a href="<?php 
                    echo esc_url($download_url);
                    ?>
" class="edd_download_file_link"><?php 
                    echo esc_html($file['name']);
                    ?>
</a>
								</li>
								<?php 
                    do_action('edd_receipt_files', $filekey, $file, $item['id'], $payment->ID, $meta);
                }
            } else {
                echo '<li>' . __('No downloadable files found.', 'edd') . '</li>';
Example #13
0
/**
 * Email template tag: updated_products_links
 * A list of updated products with download links included
 * 
 * @access public
 * @param mixed $payment_id
 * @return void
 */
function edd_pup_products_links_tag_plain($payment_id, $email = null)
{
    // Used to generate accurate tag outputs for preview and test emails
    if (isset($email) && absint($email) != 0) {
        $updated_products = get_post_meta($email, '_edd_pup_updated_products', true);
        $updated_products = is_array($updated_products) ? $updated_products : array($updated_products);
        foreach ($updated_products as $id => $name) {
            $customer_updates[$id] = array('id' => $id, 'name' => $name);
        }
    } else {
        $email = get_transient('edd_pup_sending_email_' . get_current_user_id());
        $updated_products = get_post_meta($email, '_edd_pup_updated_products', true);
        $updated_products = is_array($updated_products) ? $updated_products : array($updated_products);
        $customer_updates = edd_pup_get_customer_updates($payment_id, $email);
        $customer_updates = is_array($customer_updates) ? $customer_updates : array($customer_updates);
    }
    $filters = get_post_meta($email, '_edd_pup_filters', true);
    if ($customer_updates) {
        $show_names = apply_filters('edd_pup_email_show_names', true);
        $payment_data = edd_get_payment_meta($payment_id);
        // Set email to most recent email if it's been changed from initial email
        if (isset($payment_data['user_info']['email']) && $payment_data['user_info']['email'] != $payment_data['email']) {
            $payment_data['email'] = $payment_data['user_info']['email'];
        }
        // Used for detecting when to place commas
        $c = 1;
        $download_list = '';
        foreach ($customer_updates as $item) {
            if (edd_use_skus()) {
                $sku = edd_get_download_sku($item['id']);
            }
            $price_id = edd_get_cart_item_price_id($item);
            if ($show_names) {
                $title = $c == 1 ? $item['name'] : ', ' . $item['name'];
                if (!empty($sku)) {
                    $title .= "&nbsp;&ndash;&nbsp;" . __('SKU', 'edd') . ': ' . $sku;
                }
                $download_list .= apply_filters('edd_pup_email_products_link_title_plain', $title, $item, $price_id, $payment_id);
            }
            $files = edd_get_download_files($item['id'], $price_id);
            if ($files) {
                // $f used for detecting when to place commas
                $f = 1;
                $download_list .= ' (';
                foreach ($files as $filekey => &$file) {
                    $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $item['id'], $price_id);
                    $download_list .= $f == 1 ? edd_get_file_name($file) . ': ' . esc_url($file_url) : ', ' . edd_get_file_name($file) . ': ' . esc_url($file_url);
                    $f++;
                }
                $download_list .= ')';
            }
            if (edd_is_bundled_product($item['id'])) {
                $b = 1;
                $bundled_products = edd_get_bundled_products($item['id']);
                $download_list .= "&nbsp;&ndash;&nbsp;";
                foreach ($bundled_products as $bundle_item) {
                    if ($filters['bundle_1'] == 'all' || isset($updated_products[$bundle_item])) {
                        $download_list .= $b == 1 ? get_the_title($bundle_item) : '; ' . get_the_title($bundle_item);
                        $fb = 1;
                        $bundlefiles = edd_get_download_files($bundle_item);
                        $download_list .= ' (';
                        foreach ($bundlefiles as $bundlefilekey => $bundlefile) {
                            $bundlefile_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $bundlefilekey, $bundle_item, $price_id);
                            $download_list .= $fb == 1 ? $bundlefile['name'] . ': ' . esc_url($bundlefile_url) : ', ' . $bundlefile['name'] . ': ' . esc_url($bundlefile_url);
                            $fb++;
                        }
                        $download_list .= ')';
                    }
                    $b++;
                }
            }
            if ('' != edd_get_product_notes($item['id'])) {
                $download_list .= ' &ndash; ' . edd_get_product_notes($item['id']);
            }
            $c++;
        }
        return $download_list;
    }
}
 /**
  * Returns the link to the file available for download
  *
  * @since 0.1
  */
 function eddflg_build_download_url($payment_id)
 {
     $downloads = edd_get_payment_meta_cart_details($payment_id, true);
     $purchase_data = edd_get_payment_meta($payment_id);
     if ($downloads) {
         $price_id = edd_get_cart_item_price_id($downloads[0]);
         $download_files = edd_get_download_files($downloads[0]['id'], $price_id);
     }
     foreach ($download_files as $filekey => $file) {
         $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $downloads[0]['id'], $price_id);
     }
     return $download_url;
 }
                        }
                    } elseif (edd_is_bundled_product($item['id'])) {
                        $bundled_products = edd_get_bundled_products($item['id']);
                        foreach ($bundled_products as $bundle_item) {
                            ?>
									<li class="edd_bundled_product">
										<span class="edd_bundled_product_name"><?php 
                            echo get_the_title($bundle_item);
                            ?>
</span>
										<ul class="edd_bundled_product_files">
											<?php 
                            $download_files = edd_get_download_files($bundle_item);
                            if ($download_files && is_array($download_files)) {
                                foreach ($download_files as $filekey => $file) {
                                    $download_url = edd_get_download_file_url($meta['key'], $email, $filekey, $bundle_item, $price_id);
                                    ?>
													<li class="edd_download_file">
														<a href="<?php 
                                    echo esc_url($download_url);
                                    ?>
" class="edd_download_file_link"><?php 
                                    echo esc_html($file['name']);
                                    ?>
</a>
													</li>
													<?php 
                                    do_action('edd_receipt_bundle_files', $filekey, $file, $item['id'], $bundle_item, $payment->ID, $meta);
                                }
                            } else {
                                echo '<li>' . __('No downloadable files found for this bundled item.', 'easy-digital-downloads') . '</li>';