WordPress从主题中删除插件过滤器



我需要从插件woocommerce-wholesale-pro中删除过滤器。过滤器被添加到文件中 woocommerce-批发-定价-pro.php它看起来像这样:

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

到目前为止,我已经尝试将其添加到函数中.php在我的主题中:

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

我也尝试添加:

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

后:

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

在 init(( 函数中的插件文件中,但它不起作用。但是当我把它改成这个时:

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

它有效。

有什么方法可以从我的主题中删除此过滤器吗?

您可以使用以下方法

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

最新更新