This snippet ensures that customers can easily find and access their downloadable products directly from their account.
add_action('woocommerce_account_downloads_endpoint', 'custom_display_downloads');
function custom_display_downloads() {
$downloads = WC()->customer->get_downloads();
if (!empty($downloads)) {
echo '<h2>' . __('My Downloads', 'woocommerce') . '</h2>';
foreach ($downloads as $download) {
echo '<div class="download">';
echo '<a href="' . esc_url($download['file']) . '">' . esc_html($download['name']) . '</a>';
echo '<p>' . __('Expiry Date: ', 'woocommerce') . esc_html($download['access_expires']) . '</p>';
echo '</div>';
}
} else {
echo '<p>' . __('No downloads available.', 'woocommerce') . '</p>';
}
}