Hide the Downloads Tab When There Are No Downloads
Removes the Downloads item from the My Account menu for customers who have never bought a downloadable product.
Opens WPIDE on
Code
add_filter( 'woocommerce_account_menu_items', function ( $items ) {
if ( isset( $items['downloads'] ) && is_user_logged_in() && ! wc_get_customer_available_downloads( get_current_user_id() ) ) {
unset( $items['downloads'] );
}
return $items;
}, 20 );
Notes
The tab reappears automatically after a customer buys something downloadable.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.