删除插件类中定义的操作 [英] Remove action defined within plugin class
本文介绍了删除插件类中定义的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个电子商务主题。 我已经安装了WooCommerce PayPal Checkout Payment Gateway付款插件,并且我想更改此结账按钮的位置,我尝试删除_action显示结账按钮,但它不起作用,在这种情况下如何删除操作?
Hook in plugin file:
plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-with-spb.php
这是我在functions.php
文件中的代码,它不起作用:
function remove_anon_filters( $name, $functionname, $priority ) {
global $wp_filter;
foreach ( $wp_filter[ $name ][ $priority ] as $key => $data ) {
if ( stripos( $key, $functionname ) ) {
remove_action( $name, $key, $priority );
}
}
}
add_action( 'plugins_loaded', 'demo_init', 999 );
function demo_init() {
remove_anon_filters( 'woocommerce_review_order_after_submit', 'display_paypal_button', 10 );
}
// or.
add_action( 'init', 'remove_init', 999 );
function remove_init() {
remove_action( 'woocommerce_review_order_after_submit', array( 'WC_Gateway_PPEC_With_SPB', 'display_paypal_button' ), 10 );
}
感谢您的帮助。
推荐答案
若要删除非静态方法,应实例化该类,并删除wp_head
https://developer.wordpress.org/reference/functions/remove_action/
此外,Remove_action应该与Add操作具有相同的优先级,在本例中未指定该操作。
add_action( 'wp_head', 'remove_ppec_with_spb', 10);
function remove_ppec_with_spb() {
$class = new WC_Gateway_PPEC_With_SPB;
remove_action( 'woocommerce_review_order_after_submit', array( $class , 'display_paypal_button' ) );
}
这篇关于删除插件类中定义的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文