Join

Hide WooCommerce Downloads Endpoint if User Has Nothing to Download

Don't want to mess with code snippets? Request for this to be a feature of MyListing Pro.

Instructions

  1. Create a new PHP code snippet.
  2. Copy the contents of code snippet below.
  3. Paste the contents into your code snippet.
  4. Review any notes that I’ve provided.
  5. Save and enable the code snippet.
  6. Test.

Snippet

By default, if any of your products are marked as downloadable, WooCommerce will display a ‘Downloads’ My Account endpoint. This happens even if a user has nothing to download (i.e., they never purchased/obtained a downloadable product).

PHP
add_filter( 'woocommerce_account_menu_items', 'wptu_hide_downloads_tab_my_account', 9999 );
 
function wptu_hide_downloads_tab_my_account( $items ) {
    $downloads = ! empty( WC()->customer ) ? WC()->customer->get_downloadable_products() : false;
    $has_downloads = (bool) $downloads;
    if ( ! $has_downloads ) unset( $items['downloads'] );
    return $items;
}