WordPress - remove action defined within plugin class
Whenever $wc_lg = new WC_List_Grid()
is instantiated, its going to trigger wp
hook. Right after global WP class object is set up, the instance $wg_lg
is going to call setup_gridlist()
on itself. Its going to trigger woocommerce_before_shop_loop
hook. And whenever that happens, again $wg_lg
is going to call a function on itself. Namely gridlist_toggle_button()
.
I want to change the content of the gridlist_toggle_button function
Why not just to change it inside plugin ? Like override everything whats inside it.
global $WC_List_Grid;
How do you know that $WC_List_Grid
has its name? Its just a class name. It can be instantiated under any name like $foo
or $bar
.
I assume that you are coding in functions.php file of your template. Plugins are being loaded before functions.php and remove_action()
can only work after add_action()
happend.
Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.
So this should actually work just for removing the action, but how that helps you to change content inside of the function? :
remove_action( 'woocommerce_before_shop_loop', array('WC_List_Grid', 'gridlist_toggle_button'), 30);
Notice that you were using priority 100
EDIT
I found out that do_action('woocommerce_archive_description')
happens in archive-product.php and in wc-template-functions.php right before woocommerce_before_shop_loop
hook actions are being executed in plugin. Try to use this:
function remove_plugin_actions(){ global $WC_List_Grid; remove_action( 'woocommerce_before_shop_loop', array( $WC_List_Grid, 'gridlist_toggle_button' ), 30); }add_action('woocommerce_archive_description','remove_plugin_actions');