我正试图使用remove_action来阻止插件的一部分运行-不要问我为什么:-)。
插件中的功能是:
add_action( 'woocommerce_before_single_product_summary', array( $this, 'show_product_gallery' ), 30 );
我正试图通过以下方式删除它:
remove_action( 'woocommerce_before_single_product_summary', array( $this, 'show_product_gallery' ), 30 );
出于某种原因,它没有起到作用,尽管这通常在Wordpress/WooCommerce中有效。
有人能解释一下为什么会这样吗?我还尝试将我的功能与其他东西挂钩,例如
add_action( 'init', 'remove_it' );
function remove_it() {
remove_action( 'woocommerce_before_single_product_summary', array( $this, 'show_product_gallery' ), 30 );
}
(插件代码:https://codedump.io/share/axGWwMwAH0vn/1/linzs-hook-not-working)干杯,
林茨
编辑:这个问题与上一个关于remove_action不起作用的问题不同,因为这与错误的优先级有关,而这个优先级在30时是正确的。
您需要全局访问类变量。请试试这个。
add_action( 'wp', 'remove_it' );
function remove_it() {
global $WC_Product_Gallery_slider;
remove_action( 'woocommerce_before_single_product_summary', array( $WC_Product_Gallery_slider, 'show_product_gallery' ), 30 );
}