Remove a metabox registered by another plugin – Woocommerce

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

Read More

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.

Related posts

2 comments

  1. 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. 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 );
    

Comments are closed.