Daniel Koczuła
Daniel Koczuła

Reputation: 1034

Wordpress remove plugin filter from theme

I need to remove filter from plugin woocommerce-wholesale-pro. Filter is added in file woocommerce-wholesale-pricing-pro.php and it looks like this:

class IGN_Wholesale_Pro_Suite {
    function init() {
        add_filter( 'loop_shop_post_in', array( $this, 'product_filter' ) );

        ...
    }

    function product_filter( $meta_query = array() ) {
        ...
    }
}

So far I've tried adding this to functions.php in my theme:

function removeIGNfilter()
{
    remove_filter( 'loop_shop_post_in', array('IGN_Wholesale_Pro_Suite', 'product_filter') );
}
add_action('init','removeIGNfilter', 15);
add_action('plugins_loaded','removeIGNfilter', 15);

I've tried also adding:

remove_filter( 'loop_shop_post_in', array('IGN_Wholesale_Pro_Suite', 'product_filter') );

after:

add_filter( 'loop_shop_post_in', array( $this, 'product_filter' ) );

in plugins file in init() function but it doesn't work. But when I change it to this:

remove_filter( 'loop_shop_post_in', array($this, 'product_filter') );

It works.

Is there any way I can remove this filter from my theme?

Upvotes: 0

Views: 610

Answers (1)

Ahir Chetan
Ahir Chetan

Reputation: 42

You can use for this below method

// below code is only testing not used to functions.php


class IGN_Wholesale_Pro_Suite {
function init() {
    add_filter( 'loop_shop_post_in', array( $this, 'product_filter' ) );
}
function product_filter( $meta_query = array() ) {
}
}

//only user for below code
$plugin_class_name = new IGN_Wholesale_Pro_Suite();
remove_action('loop_shop_post_in', array($plugin_class_name, 'product_filter'));

Upvotes: 0

Related Questions