1

I have tried so many solutions for this but I can't figure it out. Here is a simplified version of the plugin code:

class YITH_Vendors_Frontend_Premium extends YITH_Vendors_Frontend {
    public function __construct() {

    add_action( 'woocommerce_register_form', array( $this, 'register_form' ) );
}

So I want to remove this action from my child themes function.php.

The problem is the class is not instanced via a variable. Instead it is instanced like this:

class YITH_Vendors_Premium extends YITH_Vendors {
public function __construct() {
public function init() {
            $this->frontend = new YITH_Vendors_Frontend_Premium();
    }
  }
}

This class however is never being instanced via variable. Instead there is a function that instances it:

function YITH_Vendors() {

    if ( defined( 'YITH_WPV_PREMIUM' ) ) {
        return YITH_Vendors_Premium::instance();
    }

    return YITH_Vendors::instance();
  }

And then it's just called like that:

YITH_Vendors();

I tried all these but no chance:

remove_action( 'woocommerce_register_form', array( "YITH_Vendors_Frontend", 'register_form' ), 999 );
remove_action( 'woocommerce_register_form', array( "YITH_Vendors_Frontend_Premium", 'register_form' ), 999 );
remove_action( 'woocommerce_register_form', array( "YITH_Vendors", 'register_form' ), 999 );
remove_action( 'woocommerce_register_form', array( "YITH_Vendors_Premium", 'register_form' ), 999 );

Please help! Thanks!

0

You'll want to find the right action to call this. After the action has been added, but before it is called. Then get the object's instance of the callback and the same priority (10 is default).

remove_action('woocommerce_register_form', array ( YITH_Vendors_Premium::instance()->frontend, 'register_form' ), 10 );
  • Thanks! I finally ended up using your solution like this: function remove_vendor_reg() { remove_action('woocommerce_register_form', array ( YITH_Vendors_Premium::instance()->frontend, 'register_form' ), 10 ); } add_action( 'woocommerce_register_form_start', 'remove_vendor_reg' ); – Daniel Klose Mar 26 '16 at 3:30
0

It will not work using a simple remove_action, you need a custom function to replace as anonymous object. Also make sure it trigger after the 'woocommerce_product_query' filter has been set.

Try this function:

function remove_anonymous_object_filter( $tag, $class, $method ) 
                {
                    $filters = false;

                    if ( isset( $GLOBALS['wp_filter'][$tag] ) )
                        $filters = $GLOBALS['wp_filter'][$tag];

                    if ( $filters )
                    foreach ( $filters as $priority => $filter ) 
                        {
                            foreach ( $filter as $identifier => $function ) 
                                {
                                    if ( ! is_array( $function ) )
                                        continue;

                                    if ( ! $function['function'][0] instanceof $class )
                                        continue;

                                    if ( $method == $function['function'][1] ) 
                                        {
                                            remove_filter($tag, array( $function['function'][0], $method ), $priority);
                                        }
                                }
                        }
                }

For your particular filter you should try this:

remove_anonymous_object_filter('woocommerce_product_query',             'YITH_Vendors_Frontend_Premium', 'hide_vendors_product');

You should also check if the anonymous object filter exists, use this functio:

function anonymous_object_filter_exists($tag, $class, $method)
                {
                    if ( !  isset( $GLOBALS['wp_filter'][$tag] ) )
                        return FALSE;

                    $filters = $GLOBALS['wp_filter'][$tag];

                    if ( !  $filters )
                        return FALSE;

                    foreach ( $filters as $priority => $filter ) 
                        {
                            foreach ( $filter as $identifier => $function ) 
                                {
                                    if ( ! is_array( $function ) )
                                        continue;

                                    if ( ! $function['function'][0] instanceof $class )
                                        continue;

                                    if ( $method == $function['function'][1] ) 
                                        {
                                            return TRUE;
                                        }
                                }
                        }

                    return FALSE;
                }

Then use this:

if (anonymous_object_filter_exists('woocommerce_product_query',             'YITH_Vendors_Frontend_Premium', 'hide_vendors_product'))
    { .. }
  • Hi, Thank you for your answer but I am afraid this is not working. What I am trying to achieve is to remove a registration option on the registration page. From what i understand in your code, what you are trying to do is to remove vendor products from being listed. Also where do you get the method 'hide_vendors_product' from? Thanks – Daniel Klose Mar 26 '16 at 2:25
  • I am an idiot! I accidentally added the wrong action to my explanation :) I corrected it now! – Daniel Klose Mar 26 '16 at 2:27
  • Still seeing the problem after adjusting your code. I noticed you have remove_filter in your function, tho I want to remove an action. However, I read somewhere, actions are just fancy filters, so if that's case then I believe you are correct. Any other ideas what I could do? – Daniel Klose Mar 26 '16 at 2:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.