John Davidson

php - Remove action from a plugin

0 comments
Message:


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


My Answer:
To remove the action added by the plugin in your child theme, you need to make sure you are using the correct function name and priority. Here is the correct way to remove the action:

php
add_action( 'init', 'remove_plugin_action' );
function remove_plugin_action() {
remove_filter( 'woocommerce_order_item_get_formatted_meta_data', [ $GLOBALS['plugin_class_instance'], 'hide_extra_data' ] );
}


Make sure to replace `$GLOBALS['plugin_class_instance']` with the actual variable or object instance that holds the plugin class. This code should be added to your child theme's functions.php file.

Rate this post

5 of 5 based on 4416 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us