admin管理员组

文章数量:1434960

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

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

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

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

Share Improve this question asked Apr 2, 2019 at 8:56 jasawebjasaweb 519 bronze badges 4
  • Which plugin is used for custom product data tabs? So I can clearly understand and will help you. – Tanmay Patel 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. – Tanmay Patel Commented Apr 2, 2019 at 9:35
  • Here is the theme link themeforest/item/… – jasaweb Commented Apr 2, 2019 at 11:00
Add a comment  | 

2 Answers 2

Reset to default 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!

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.

本文标签: Hide tabs on woocommerce product editor for user role