Hide Downloads Tab on WooCommerce My Account if Customer has no Downloadable Products

By default, the Downloads tab in the WooCommerce My Account area will show regardless of if the customer has any downloadable products or not.

With this simple snippet, you can change this behavior to only show the Downloads tab if the customer has something that they can download.

add_filter( 'woocommerce_account_menu_items', 'snippetpress_remove_empty_downloads_link' );

function snippetpress_remove_empty_downloads_link( $items ) {   
    if (!is_admin()){       
        $downloads     = WC()->customer->get_downloadable_products();
        $has_downloads = (bool) $downloads;
        if ( !$has_downloads) {
            unset($items['downloads']);
        }       
    }   
    return $items;
}

Where to add the snippet?

Whichever snippet you choose to use, you should place it at the bottom of the functions.php file of your child theme. Make sure you know what you’re doing when editing this file. Alternatively, you can use a plugin such as Code Snippets to add the custom code to your WordPress site. If you need further guidance on how to add the code, check out our post on How to Add WordPress Snippets.