skip to Main Content

WordPress Code Snippets


Add Custom Message for Expiring Downloads on My Account Page

This snippet helps notify users about their downloadable products that are close to expiry, improving user experience.

add_action('woocommerce_account_downloads_endpoint', 'custom_expiry_message_for_downloads');
function custom_expiry_message_for_downloads() {
    $downloads = WC()->customer->get_downloads();
    foreach ($downloads as $download) {
        if ($download['access_expires'] && strtotime($download['access_expires']) < time() + 7 * DAY_IN_SECONDS) {
            echo '<p>' . __('Your download for', 'woocommerce') . ' ' . esc_html($download['name']) . ' ' . __('will expire soon.', '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