I’m trying to not to edit files directly in the plugin but i don’t want the plugin’s actions to execute.
Here is the code:-
class YITH_WC_Points_Rewards_Earning {
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* Initialize plugin and registers actions and filters to be used
*
* @since 1.0.0
* @author Emanuela Castorina
*/
public function __construct() {
add_action( 'woocommerce_payment_complete', array( $this, 'add_order_points' ) );
add_action( 'woocommerce_order_status_processing', array( $this, 'add_order_points' ) );
add_action( 'woocommerce_order_status_completed', array( $this, 'add_order_points' ) );
}
}
function YITH_WC_Points_Rewards_Earning() {
return YITH_WC_Points_Rewards_Earning::get_instance();
}
I don’t want the actions in the plugin’s class to execute, so what I tried was this in my custom file which was in functions.php
remove_action( 'woocommerce_payment_complete', array( YITH_WC_Points_Rewards_Earning(), 'add_order_points' ) );
remove_action( 'woocommerce_order_status_processing', array( YITH_WC_Points_Rewards_Earning(), 'add_order_points' ));
remove_action( 'woocommerce_order_status_completed', array( YITH_WC_Points_Rewards_Earning(), 'add_order_points' ));
But still the plugin’s actions get executed, i checked by wc_logger that YITH_WC_Points_Rewards_Earning() this is being sucessfully called in my custom file . So,how to make the plugin’s actions not work?.Thanks
2
Answers
Adding all the remove everything in an 'init' action closure function did the job :).
Use a priority of about 20 (or maybe higher), so that the remove_action is executed after the instance of the class is created, assuming that your code is able to access the instance of the class created by the plugin. From the wordpress function description – “If an action has been added from within a class, for example by a plugin, removing it will require accessing the class variable. It is also worth noting that you may need to prioritise the removal of the action to a hook that occurs after the action is added. You cannot successfully remove the action before it has been added.”