/**
* Gets a user's downloadable products if they are logged in.
*
* @access public
* @return array Array of downloadable products
*/
function get_downloadable_products()
{
global $wpdb;
$downloads = array();
if (is_user_logged_in()) {
$user_info = get_userdata(get_current_user_id());
$results = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "woocommerce_downloadable_product_permissions WHERE user_id = '%s';", get_current_user_id()));
if ($results) {
foreach ($results as $result) {
if ($result->order_id > 0) {
$order = new WC_Order($result->order_id);
if ($order->status != 'completed' && $order->status != 'processing') {
continue;
}
$product_post = get_post($result->product_id);
if (!$product_post) {
continue;
}
if ($product_post->post_type == 'product_variation') {
$_product = new WC_Product_Variation($result->product_id);
} else {
$_product = new WC_Product($result->product_id);
}
if ($_product->exists()) {
$download_name = $_product->get_title();
} else {
$download_name = '#' . $result->product_id;
}
$downloads[] = array('download_url' => add_query_arg('download_file', $result->product_id, add_query_arg('order', $result->order_key, add_query_arg('email', $result->user_email, home_url()))), 'product_id' => $result->product_id, 'download_name' => $download_name, 'order_id' => $order->id, 'order_key' => $order->order_key, 'downloads_remaining' => $result->downloads_remaining);
}
}
}
}
return apply_filters('woocommerce_customer_get_downloadable_products', $downloads);
}