Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created August 15, 2025 15:58
Show Gist options
  • Save greenhornet79/6c6a37cda271157818662c58cf779a84 to your computer and use it in GitHub Desktop.
Save greenhornet79/6c6a37cda271157818662c58cf779a84 to your computer and use it in GitHub Desktop.
<?php
add_shortcode('endo_user_purchased_downloads', function () {
if (! is_user_logged_in()) {
return '<p>Please log in to see your downloads.</p>';
}
$user_id = get_current_user_id();
$downloads_raw = function_exists('wc_get_customer_available_downloads')
? wc_get_customer_available_downloads($user_id)
: [];
if (empty($downloads_raw)) {
return '<p>No purchased downloads yet.</p>';
}
ob_start();
?>
<ul class="user-purchased-downloads">
<?php foreach($downloads_raw as $data ) {
?>
<li>
<?php
echo '<a href="' . $data['download_url'] . '">' . $data['product_name'] . '</a>';
?>
</li>
<?php
} ?>
</ul>
<?php
return ob_get_clean();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment