Skip to main content

While working on a project recently that uses WooCommerce & Dokan, I was trying to remove the Inventory section from the Product Edit page. Using Query Monitor I was able to determine that the page template that is being called is new-product-single.php. After some trial and error I found this section of code that removed what I wanted, but it also removed several things I didn’t want it to remove

<?php do_action( 'dokan_product_edit_after_main', $post, $post_id ); ?>

The next thing I did was open up grepWin and figure out where the function ‘dokan_product_edit_after_main‘ was being added. I was able to find it in wp-content/plugins/dokan-lite/includes/Dashboard/Templates/Products.php

add_action( 'dokan_product_edit_after_main', array( __CLASS__, 'load_inventory_template' ), 5, 2 );
add_action( 'dokan_product_edit_after_main', array( __CLASS__, 'load_downloadable_template' ), 10, 2 );

The action I want to remove is called:  load_inventory_template(). I tried the following bit of code but it wasn’t working:

add_action('plugins_loaded', 'remove_dokan_inventory', 1);
function remove_dokan_inventory() {
	remove_action( 'dokan_product_edit_after_main', 'load_inventory_template', 5 );
}

I remembered stumbling across a similar problem a while back and decided to give it a try here as well. I created a file called hard-unregister.php and included it in my plugin (or functions.php file of your child theme). The contents of hard-unregister.php are in the gist below. Here’s the working example:

add_action('wp', 'remove_inventory_from_product_edit_page', 1);
function remove_inventory_from_product_edit_page()
{
    do_hard_unregister_object_callback('dokan_product_edit_after_main', 5, 'load_inventory_template');
}

When to use it?

When you see this: :: and not this: ->

WeDevs\D\D\T\Products::load_inventory_template()

The normal remove_action() / remove_filter() methods should work if you see this:

Dokan_Geolocation_Vendor_Dashboard->add_product_editor_options()

Leave a Reply