How to hide/remove Restrictions Tab in WooCommerce Product Data page? Please help!

  • Our resources on Babiato Forum is CLEAN and SAFE. So you can use it for development or production. But sometime the antivirus will warn the JS code. It's no problem. So before downloading, you need to disable the antivirus tools and then enjoy your "Party"!

mrPoor

New member
Jul 29, 2020
6
1
3
Hi,
I'm using WooCommerce and WooCommerce Catalog Visibility Options plugins.
I want to remove some tabs in product data box, such as General, Inventory, Shipping and Restrictions tabs. I have removed the first three tabs, except for the Restrictions, by adding the code below in functions.php:
PHP:
You don't have permission to view the code content. Log in or register now.
From researching, I know that the Restrictions tab is added by WooCommerce Catalog Visibility Options plugin. I dig round into the source code and I found the way how the Restrictions was added:
PHP:
You don't have permission to view the code content. Log in or register now.
I also tried this:
PHP:
You don't have permission to view the code content. Log in or register now.
But it didn't work at all. I'm kind new to php, can anyone help me to remove the restrictions tab properly?
 
Last edited:

frizzel

Active member
Jun 13, 2019
157
110
43
The function add_tab is part of the Class "WC_Catalog_Restrictions_Product_Admin", so I was hoping this would work after the plugin was loaded. Apparently not.
One more suggestion:
PHP:
You don't have permission to view the code content. Log in or register now.
If that also doesn't work, I'm out of ideas, sorry.
 

mrPoor

New member
Jul 29, 2020
6
1
3
The function add_tab is part of the Class "WC_Catalog_Restrictions_Product_Admin", so I was hoping this would work after the plugin was loaded. Apparently not.
One more suggestion:
PHP:
You don't have permission to view the code content. Log in or register now.
If that also doesn't work, I'm out of ideas, sorry.
Unfortunately, it doesn't work :(. However, there was a friend who answer me on stackoverflow as below:

In meta-boxes/views/html-product-data-panel.php on line 41-48 we find
<ul class="product_data_tabs wc-tabs">
<?php foreach ( self::get_product_data_tabs() as $key => $tab ) : ?>
<li class="<?php echo esc_attr( $key ); ?>_options <?php echo esc_attr( $key ); ?>_tab <?php echo esc_attr( isset( $tab['class'] ) ? implode( ' ', (array) $tab['class'] ) : '' ); ?>">
<a href="#<?php echo esc_attr( $tab['target'] ); ?>"><span><?php echo esc_html( $tab['label'] ); ?></span></a>
</li>
<?php endforeach; ?>
<?php do_action( 'woocommerce_product_write_panel_tabs' ); ?>
</ul>
self::get_product_data_tabs() refers to meta-boxes/class-wc-meta-box-product-data.php line 82 which then contains woocommerce_product_data_tabs
/**
* Return array of tabs to show.
*
* @return array
*/
private static function get_product_data_tabs() {
$tabs = apply_filters(
'woocommerce_product_data_tabs',
array(
...
So woocommerce_product_write_panel_tabs runs after the foreach loop
To remove an action you need to pass the same callable that was used to add the action in the first place. Note the use of $this
add_action( 'woocommerce_product_write_panel_tabs', array( $this, 'add_tab' ) );
So when you remove the action you need to pass the same instance the same way:
remove_action( 'woocommerce_product_write_panel_tabs', array( $that, 'add_tab' ) );
Where $that is a variable containing the same instance of the class. To do this you need to find that variable. This depends on how the plugin was originally built.
But I just can't understand the explanation in that post. Can you please be so kind to take a look and if whether it make any sense to you?

Thank you very much!
 
Last edited:

frizzel

Active member
Jun 13, 2019
157
110
43
Finally found the solution, thanks to davelavoie:
PHP:
You don't have permission to view the code content. Log in or register now.
The method above allows to remove filters/actions with a callback to a class you don't have access to.

Personally, I would just comment that action line in the plug-in and make a note to do it again, when the plug-in is updated.
 
  • Love
Reactions: mrPoor

mrPoor

New member
Jul 29, 2020
6
1
3
Finally found the solution, thanks to davelavoie:
PHP:
You don't have permission to view the code content. Log in or register now.
The method above allows to remove filters/actions with a callback to a class you don't have access to.

Personally, I would just comment that action line in the plug-in and make a note to do it again, when the plug-in is updated.
Wow, it really works. Thank you very many!!! :D:D:D
 

Similar threads