Download link in the loop that a customer have bought


Im running basic product loop with featured image and title. Under that I want download link to be available if the user has bought that digital product.

I tried this but it shows downloadable bought product links under all products in the loop.

global $product;

$downloads = array();

$user_id = get_current_user_id();

$downloads = wc_get_customer_available_downloads($user_id);

if (!empty($downloads)) {

foreach ($downloads as $download) {

if ($download['product_id'] === $product->get_id()) {

echo '<a href="' . $download['download_url'] . '">Download</a>';


I want the downloadable links (that the customer has bought) to be under the bought products only.

, Muhammad Adnan Bashir 3 years 2020-06-01T09:12:27-05:00 0 Answers 88 views 0

Leave an answer