skip to Main Content

WordPress Code Snippets


Display Downloadable Products on the WooCommerce My Account Page

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>';
    }
}

I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search