remove_action 不适用于插件中的函数
remove_action not working for functions within a plugin
我正在尝试使用 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 时是正确的。
您需要全局访问 class 变量。请试试这个。
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 );
}
我正在尝试使用 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 时是正确的。
您需要全局访问 class 变量。请试试这个。
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 );
}