2

I need help how to hide custom product data tabs (created by plugins) for custom user role on product page editor (see image).

enter image description here

I think it suppose to be done by modifying its CSS and apply it on functions.php

Already try and play with the below code and add the element in it, but not working.

// Remove Product Data Tabs Options on product page editor
add_filter('woocommerce_product_data_tabs' , 'hide_wc_product_tabs' );

function hide_wc_product_tabs($tabs) {

  if (!current_user_can('yith_vendor')) {  // replace role ID with your own
      return $tabs;
  }

  //what code should I implement here

  return $tabs;
}

Any help appreciate. thank you

4
  • Which plugin is used for custom product data tabs? So I can clearly understand and will help you. Commented Apr 2, 2019 at 9:17
  • what @Karun said below solved the problem but not all, the tab created by plugin should be hide is Epeken and the additional extra tab created by the theme.
    – jasaweb
    Commented Apr 2, 2019 at 9:27
  • Can you please let me know theme name or give me website URL. So I can check it. Commented Apr 2, 2019 at 9:35
  • Here is the theme link themeforest.net/item/…
    – jasaweb
    Commented Apr 2, 2019 at 11:00

2 Answers 2

1

So using your code as reference, you could do something like:

function hide_wc_product_tabs( $tabs ) {
    if ( ! current_user_can( 'yith_vendor' ) ) {
        return $tabs;
    }

    unset( $tabs['inventory'] ); // Removes the inventory tab.

    return $tabs;
}

add_filter( 'woocommerce_product_data_tabs' , 'hide_wc_product_tabs' );

These are the default WooCommerce product tabs:

Array ( [0] => general [1] => inventory [2] => shipping [3] => linked_product [4] => attribute [5] => variations [6] => advanced )

Hope it helps!

4
  • I get it, but what I need to hide additional custom tabs created by specific plugins. I think it suppose to be done by modifying its CSS and apply it in the code.
    – jasaweb
    Commented Apr 2, 2019 at 9:07
  • @jasaweb You can do what @Karun suggested in his answer, do a var_dump($tabs) so you can see what is the key for each tab, and then unset what you don't need.
    – djboris
    Commented Apr 2, 2019 at 9:10
  • @jasaweb So you can add this line before that unset: var_dump( array_keys( $tabs ) ); It will print the "name" for all the tabs that are available, then you can unset the ones you want to. Commented Apr 2, 2019 at 9:10
  • ok going to try
    – jasaweb
    Commented Apr 2, 2019 at 9:12
0

The $tabs will return an array. Before the line return $tabs; you should check the key in the array and unset it. You can use var_dump to check what the array contains if you're unsure of the key name.

3
  • thanks, it works but I only got one key name from the tabs, how to get the other tabs key name?
    – jasaweb
    Commented Apr 2, 2019 at 9:23
  • $tabs should return all the available keys. Try increasing the priority value on add_filter and keep on debugging using var_dump
    – Karun
    Commented Apr 2, 2019 at 9:26
  • 1
    still no luck after increasing the priority value. any other method?
    – jasaweb
    Commented Apr 2, 2019 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.