• Resolved vladduma

    (@vladduma)


    Is there any way to hide custom tab(s) if user is not logged in?
    I want to display certain downloadable data, but only to logged in users.

    Right now I am using this code in functions.php:

    	if( $product->has_attributes() AND !is_user_logged_in() ) {
            unset( $tabs['additional_information'] );   
        }
    

    To hide attributes tabs. Is something like this possible with custom tabs?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @vladduma,

    Yes this is possible!

    Try adding this to your functions.php file.

    add_filter( 'yikes_woo_filter_all_product_tabs', 'yikes_woo_hide_tabs_from_non_logged_in_users', 10, 2 );
    
    function yikes_woo_hide_tabs_from_non_logged_in_users( $tabs, $product ) {
    
    	if ( isset( $tabs['additional_information'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['additional_information'] );
    	}
    
    	return $tabs;
    }

    Cheers,
    Kevin.

    Thread Starter vladduma

    (@vladduma)

    Hmm doesn’t work…
    Don’t you have a separate constant for custom tabs? Shouldn’t [‘additional_information’] be smth like [‘custom_product_tabs’]?

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    I should have explained that better. The value additional_information should be replaced with the slug of your custom tab. The slug is a hyphenated version of your tab, so if you have a tab named “My Admin Tab,” you can be pretty sure that the slug will be “my-admin-tab.” If you have some complicated tab name (with special characters), then just let me know first and I will tell you what the slug should be.

    Edit:
    Also if you have multiple tabs you’re trying to restrict, let’s call them my-tab and my-tab-2, you’ll need to set the code up like this:

    add_filter( 'yikes_woo_filter_all_product_tabs', 'yikes_woo_hide_tabs_from_non_logged_in_users', 10, 2 );
    
    function yikes_woo_hide_tabs_from_non_logged_in_users( $tabs, $product ) {
    
    	if ( isset( $tabs['my-tab'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['my-tab'] );
    	}
    
    	if ( isset( $tabs['my-tab-2'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['my-tab-2'] );
    	}
    
    	return $tabs;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide tabs if user is not loged in’ is closed to new replies.