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