简体   繁体   中英

Remove action from a plugin

We use a plugin which add a filter to hide some order meta. Now we want to remove them via child theme instead of editing the plugin file. I tried every answer from here but the action is not removed: https://wordpress.stackexchange.com/questions/240929/how-to-remove-action-from-plugin and Removing action added by a plugin in Wordpress

This is the Plugin function:

public function __construct() {
   add_filter( 'woocommerce_order_item_get_formatted_meta_data', [ $this, 'hide_extra_data' ] );
}

I tried with that already, but I'm not sure if this is the right way to do it.

add_action( 'woocommerce_order_item_get_formatted_meta_data', 'remove_my_action', 1 );
function remove_my_action(){
    remove_action('woocommerce_order_item_get_formatted_meta_data', 'hide_extra_data', 10, 1);
}
remove_action( 'wp_fwoocommerce_order_item_get_formatted_meta_dataooter', 'hide_extra_data', 1 );

Try like this:

add_action( 'plugins_loaded', 'webearth_remove_plugin_filter' );
function webearth_remove_plugin_filter() {
    remove_filter( 'woocommerce_order_item_get_formatted_meta_data',
    array('ClassName', 'hide_extra_data'),
    10 );
}

Change ClassName with the name of the class used by the plugin, the Class where the constructor is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM