• Resolved davidcova

    (@davidcova)


    Hello, i saw this post and i’d like some help with it. I managed to get everything working, however, i have 2 additional tabs, i’m not an expert with php. How would i go about adding more tabs?

    Thank you.

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

    (@yikesitskevin)

    Hi @davidcova,

    Thank you for finding that support ticket for me – when I saw the subject of your support ticket I remembered that one and was going to go find it.

    The first thing we need to know is the slug of your additional tabs. If your tab is called “Description” the slug will be description; likewise if it’s called Additional Information the slug will be additional_information. For the purposes of this example, let’s call your tabs “Additional Tab 1” and “Additional Tab 2.” Therefore the slugs we’re working with are additional_tab_1 and additional_tab_2. If you need any help finding the slug of your tab (e.g. if it includes special characters), just send me a link to your product page and I will tell you the slug names.

    The second thing we need to know is the role that you want to check against. For our purposes, we’ll use the administrator role.

    The function should then look like this:

    add_filter( 'yikes_woo_filter_all_product_tabs', 'yikes_woo_add_tab_permissions', 10, 2 );
    
    function yikes_woo_add_tab_permissions( $tabs, $product ) {
    
    	if ( isset( $tabs['additional_tab_1'] ) && ! current_user_can( 'administrator' ) ) {
    		unset( $tabs['additional_tab_1'] );
    	}
    
    	if ( isset( $tabs['additional_tab_2'] ) && ! current_user_can( 'administrator' ) ) {
    		unset( $tabs['additional_tab_2'] );
    	}
    
    	return $tabs;
    }

    Make sure to replace your current function with the one above (rather than having both of them).

    Let me know how that goes.

    Cheers,
    Kevin.

    Thread Starter davidcova

    (@davidcova)

    Thank you so much for such a fast response, you fixed my issue ??

    Just so i don’t have to bother you again in the future, if i wanted to add permission to the administrator but also to an editor, how could i do that?

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey no problem.

    Do you mean you want to allow administrators and editors to see the tabs?

    That would look like:

    add_filter( 'yikes_woo_filter_all_product_tabs', 'yikes_woo_add_tab_permissions', 10, 2 );
    
    function yikes_woo_add_tab_permissions( $tabs, $product ) {
    
    	if ( isset( $tabs['additional_tab_1'] ) && ( ! current_user_can( 'administrator' ) || ! current_user_can( 'editor' ) ) ) {
    		unset( $tabs['additional_tab_1'] );
    	}
    
    	if ( isset( $tabs['additional_tab_2'] ) && ( ! current_user_can( 'administrator' ) || ! current_user_can( 'editor' ) ) ) {
    		unset( $tabs['additional_tab_2'] );
    	}
    
    	return $tabs;
    }
    Thread Starter davidcova

    (@davidcova)

    That’s it, perfect!

    Thank you so much <3

    Do you offer any support for printing the page with all created tabs contents displaying btw? ??

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    You’re welcome ??

    What do you mean by printing the page? Are you using a plugin that generates PDFs or print-friendly versions of your product pages?

    Thread Starter davidcova

    (@davidcova)

    Yes, i’m using WooCommerce ProductPrint to generate a printable page, however, the generated tabs won’t show upon printing, not sure if there’s a way to work with this or not.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    —wrong reply—

    • This reply was modified 7 years, 5 months ago by yikesitskevin.
    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    If there is a filter available we could hook into it to add the tabs but I don’t have any familiarity with that plugin. Could you ask the developer (or look through the documentation) to see if there is a way to add product meta data to the printable page?

    If you can find me a filter I can write you a function!

    Thread Starter davidcova

    (@davidcova)

    Sadly the two plugins i found that could do what i intend are long discontinued, WooCommerce PDF & Print and WooCommerce ProductPrint haven’t been updated in over 2 years. And from what i could see, there’s no much information about filters on those.

    I’m fairly new to WordPress though, perhaps if you have a suggestion, i’d gladly look into it. I only want to print the content of Woocommerce products. But only for the restrictions you added earlier.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    I have worked with folks who have used premium plugins that do this sort of thing but I have no real experience with the actual plugins so I cannot recommend them. Sorry about that.

    Thread Starter davidcova

    (@davidcova)

    I tried the code you gave for multiple viewers but the tabs disappeared for both admin and editor now :/

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Oops my mistake. This should work:

    add_filter( 'yikes_woo_filter_all_product_tabs', 'yikes_woo_add_tab_permissions', 10, 2 );
    
    function yikes_woo_add_tab_permissions( $tabs, $product ) {
    
    	if ( isset( $tabs['additional-tab-1'] ) && ! current_user_can( 'administrator' ) && ! current_user_can( 'editor' ) ) {
    		unset( $tabs['additional-tab-1'] );
    	}
    
    	if ( isset( $tabs['additional-tab-2'] ) && ! current_user_can( 'administrator' ) && ! current_user_can( 'editor' ) ) {
    		unset( $tabs['additional-tab-2'] );
    	}
    
    	return $tabs;
    }
    Thread Starter davidcova

    (@davidcova)

    That worked, thank you so much, for your support and for creating such an awesome plugin ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Hide/Show MULTIPLE Custom tab only to specific role?’ is closed to new replies.