2

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.

1

2 Answers 2

9

A quick search in their GitHub repo shows the following line:

add_meta_box(
    'woocommerce-product-images',
    __( 'Product Gallery', 'woocommerce' ),
    'WC_Meta_Box_Product_Images::output',
    'product',
    'side'
);

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.

add_action( 'add_meta_boxes' , 'remove_my_meta_boxes', 40 );
function remove_my_meta_boxes()
{
    remove_meta_box( 'woocommerce-product-images',  'product', 'side');
}
2
  • great! Thanks! I can't really say I understand it though. Why does the 'add_meta_boxes' make the difference? This is all pretty new to me I'm afraid. Feb 19, 2014 at 20:13
  • @JorgeLuisBorges That's the hook WooThemes guys use to register the box. admin_menu is another hook that runs much earlier, so you're trying to remove something that isn't even registered at that point. 40 is the priority for the callback/action as Woo uses 30 and lower.
    – kaiser
    Feb 19, 2014 at 20:16
3

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.

function remove_my_meta_boxes() {
    remove_meta_box( 'woocommerce-product-images',  'product', 'side');
}
add_action( 'add_meta_boxes' , 'remove_my_meta_boxes', 40 );

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