我正在开发一个电子商务主题。 我已经安装了WooCommerce PayPal Checkout Payment Gateway付款插件,我想更改此结帐按钮的位置,我尝试remove_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' ) );
}
关于wordpress - 删除插件类中定义的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60950435/