• Resolved alisonparsons

    (@alisoncutler)


    Hi there

    It would be really useful if I could create a tab that only I could view (with individual product details for internal use that I don’t want customers to see).

    Is this possible?

    Many thanks for your help.
    Alison

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi @alisoncutler,

    You can control the visibility of your tabs by adding a snippet like this to your functions.php file. It will remove the tab called tab-name if you aren’t an administrator.

    add_filter(
    	'yikes_woo_filter_all_product_tabs',
    	function( $tabs ) {
    		if ( ! is_admin() ) {
    			unset( $tabs['tab-name'] );
    		}
    		return $tabs;
    	}
    );

    If you aren’t comfortable editing your functions.php file, you can always use a plugin such as this one.

    Let me know if you have any questions!

    Thanks,
    Jon

    Thread Starter alisonparsons

    (@alisoncutler)

    Hi there

    I downloaded the plugin and added the php:

    add_filter(
    ‘yikes_woo_filter_all_product_tabs’,
    function( $tabs ) {
    if ( ! is_admin() ) {
    unset( $tabs[‘tab-notes’] );
    }
    return $tabs;
    }
    );

    But it is still showing that tab. Example at: https://salceyforestnursery.co.uk/product/echium-vulgare-blue-bedder/

    It is the Notes tab that I want to hide.

    • This reply was modified 4 years, 3 months ago by alisonparsons.

    Hi @alisoncutler,

    First, I would try changing the tab name in the code to notes instead of tab-notes. See if that works.

    If not, since the tab is added by another plugin it’s possible that the hook won’t work. If the other plugin provides a similar hook, you can try that. You can also try the default WooCommerce hook, named woocommerce_product_tabs.

    You’d need to update it like this:

    add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
    
    function woo_remove_product_tabs( $tabs ) {
    
       if ( ! is_admin() ) {
    	unset( $tabs['notes'] );
       }
    
        return $tabs;
    }
    • This reply was modified 4 years, 3 months ago by jpowersdev.
    Thread Starter alisonparsons

    (@alisoncutler)

    Right… I changed it to ‘notes’ and now the tab is not showing… but when logged in as admin I cannot see it?

    Thread Starter alisonparsons

    (@alisoncutler)

    also tried the second suggestion, again hides the tab – but from admin also.

    Hi @alisoncutler,

    I’m sorry, that’s my mistake. is_admin() is not the correct function to call, it’s actually current_user_can('administrator').

    If you update it to say if ( ! current_user_can('administrator') ) { it should work.

    Thanks,
    Jon

    Thread Starter alisonparsons

    (@alisoncutler)

    Perfect! That works now. Thank you very much for your help. ??

    Thread Starter alisonparsons

    (@alisoncutler)

    Sorry, forgot to tick resolved…done now…

    Great! Glad you got it working.

    Take care,
    Jon

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Is it possible to create an admin only tab?’ is closed to new replies.