• Resolved yakiimo

    (@albertof92)


    Hello,
    Is there a way to hide a custom tab to an unregistered (guest) user?
    Ty in advance!

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

    (@yikesitskevin)

    Hi @albertof92,

    Yes! We have a filter function for that. Are you familiar with adding PHP filter functions to your site?

    The following snippet will hide tabs called Additional Tab 1 and Additional Tab 2 from your site. If you have a tab called e.g. Product Information, change additional-tab-1 to product-information.

    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-tab-1'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['additional-tab-1'] );
    	}
    
    	if ( isset( $tabs['additional-tab-2'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['additional-tab-2'] );
    	}
    
    	return $tabs;
    }

    Let me know if you need any help adding the snippet to your site.

    Thank you,
    Kevin.

    Thread Starter yakiimo

    (@albertof92)

    Thanks for the reply, but seems like it’s not working.
    I created two custom tabs, called Manuals and Softwares (from the Admin panel menu, so they are saved as a template); then, I added the code.

    This is the code I inserted into the Theme’s custom CSS:

    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[‘manuals’] ) && ! is_user_logged_in() ) {
    unset( $tabs[‘manuals’] );
    }

    if ( isset( $tabs[‘softwares’] ) && ! is_user_logged_in() ) {
    unset( $tabs[‘softwares’] );
    }

    return $tabs;
    }

    I can still see the tabs both as logged in (as should be) and logged out (shouldnt be).
    Any help? ??

    Thank you again

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @albertof92,

    Where did you add this code? I just tested this and it’s working for me. Here are some screenshots to show how it’s set up.

    Saved tabs called Manuals & Softwares: https://imgur.com/a/JACdT1U

    Applying those two saved tabs to my product: https://imgur.com/a/l2ElsPc

    And the code:

    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['manuals'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['manuals'] );
    	}
    
    	if ( isset( $tabs['softwares'] ) && ! is_user_logged_in() ) {
    		unset( $tabs['softwares'] );
    	}
    
    	return $tabs;
    }

    When I am logged in I see these two tabs. When I open the page in incognito (i.e. logged out), I do not see the tabs.

    Let me know if I’ve done anything differently to you.

    Cheers,
    Kevin.

    Thread Starter yakiimo

    (@albertof92)

    Thank you for your prompt reply.
    I put the exact same code in the Custom CSS of my Bridge WordPress Theme, Custom Tabs are the same too. You can see the three pictures here (Theme Custom CSS, Custom Tabs, Tab View from LOG OUT): https://imgur.com/a/PVkhyH8

    I can still see the tabs both from logged in and logged out ??

    PS
    On the last picture you can see another custom tab (datasheet) but that should be visible to everyone, just I case you asked.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @albertof92,

    The problem is that this code is not CSS – it’s PHP. You need to add this code to your child theme’s functions.php file. If you’re not using a child theme, you could add it to your theme’s functions.php file or use a plugin like My Custom Functions.

    Hope that fixes it.

    Cheers,
    Kevin.

    Thread Starter yakiimo

    (@albertof92)

    It works!
    Thank you very much, sorry if I didn’t exactly know about the difference! You learn something new every day.

    Thanks again!

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    All good! Glad you got it working! ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide Custom Tabs’ is closed to new replies.