Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
You could give this plugin a try. –  t f Feb 19 at 19:58

2 Answers 2

up vote 2 down vote accepted

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');
}
share|improve this answer
    
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. –  JorgeLuisBorges Feb 19 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 at 20:16

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 );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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