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

  • You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

  • Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

mrPoor

New member
Jul 29, 2020
7
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
Trusted Uploader
Jun 13, 2019
359
224
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
7
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
Trusted Uploader
Jun 13, 2019
359
224
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
7
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
 

JeffSimons

New member
Aug 18, 2020
1
0
1
I'm still new to Woo Commerce and there is still a lot that I need to learn from the platform. I plan on making a fan website https://akinator.io/ and I also would want to put a merch shop in there for fans. This is the reason why I considered Woo Commerce for the platform and I'm hoping that it will be stable enough.
 

Similar threads


Forum statistics

Threads
35,268
Messages
353,670
Members
100,644
Latest member
lolcat11