0

Okay, so I am using the "FooEvents for WooCommerce" plugin for making WooCommerce products to events.

And now I wanna replace their WooCommerce hook 'woocommerce_order_status_completed' with my own.

Their hook is placed in their class and method: FooEvents_Woo_Helper::_constructor()

And that class (FooEvents_Woo_Helper) is only called by a private variable, $this->WooHelper in another class, their "main class" FooEvents.

So FooEvents_Woo_Helper is called inside FooEvents public method plugin_init():

//WooHelper
require_once($this->Config->classPath.'woohelper.php');
$this->WooHelper = new FooEvents_Woo_Helper($this->Config);

Now, I learned in another question I asked earlier about a similar question, here: How to Remove a Filter from the Admin List Table?

And I tried to do the same thing here, in different ways. But I can't make it to work. What am I doing wrong?:

function my_own_init() {
    global $FooEvents;

    if ( $FooEvents instanceof FooEvents ) {
        remove_action( 'woocommerce_order_status_completed', array( $FooEvents->WooHelper, 'process_order_tickets' ) );

    }
}
add_action( 'init', 'my_own_init', 11 );
  • To remove an non-static action from a class you need to pass the same instance that was originally hooked. This is $this->WooHelper, but because it's assigned to $this inside FooEvents you need to access that same instance of FooEvents, but you can only do that if it's instantiated into a global variable. How is it instantiated in the plugin? – Jacob Peattie Jul 4 at 12:38
  • @JacobPeattie FooEvents is instantiated as $FooEvents and is accessable as a global variable. But the $WooHelper variable inside the FooEvents class is private. – Peter Westerlund Jul 4 at 12:48
  • I'm afraid you're out of luck then. The original instance of the class that's hooked is inaccessible to you, so cannot be removed. You're not doing anything wrong, it just appears that for all intents and purposes FooEvents does not support removing this action. – Jacob Peattie Jul 4 at 12:55
  • can be done by accessing global $wp_filter, for eample see this remove_class_filter function: wpforthewin.com/remove-hook-from-class-based-wp-plugin – majick Jul 6 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.