I am trying to remove the gallery metabox which is added by WooCommerce – its been added in an update, but I already have a Gallery metabox, and I don’t want to confuse the client.
Obviously I can hack the plugin, but I’d like to do it from the functions.php
I’ve tried:
function remove_my_meta_boxes() {
remove_meta_box( 'woocommerce-product-images', 'product', 'side');
}
add_action( 'admin_menu' , 'remove_my_meta_boxes', 40 );
It doesn’t seem to work
The code that’s adding it seems to be
public function __construct() {
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 30 );
}
and
public function add_meta_boxes() {
add_meta_box( 'woocommerce-product-images', __( 'Product Gallery', 'woocommerce' ), 'WC_Meta_Box_Product_Images::output', 'product', 'side' );
}
I’ve removed sections which aren’t relevant – ie other metaboxes registered etc.
A quick search in their GitHub repo shows the following line:
So your call to
remove_meta_box()
uses the right id/handle/name as well as the right priority and context.The problem just is the hook and the priority at which the hook executes – you have to unregister later than the WooCommerce plugin registers the boxes. Else you try to deregister something that isn’t yet registered.
It should be possible to remove that metabox but you will have to remove it after it has been added. I think you are trying to do that with the priority argument but you are also using a different hook and one which, if memory server, runs before the hook being used by the plugin.