【问题标题】:Remove action defined within plugin class删除插件类中定义的操作
【发布时间】:2020-07-11 23:53:46
【问题描述】:

我正在开发一个电子商务主题。 我已经安装了WooCommerce PayPal Checkout Payment Gateway 支付插件,我想改变这个结帐按钮的位置,我尝试了remove_action显示结帐按钮,但是没有成功,在这种情况下如何删除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 );
}

感谢您的帮助,谢谢。

【问题讨论】:

  • 你能解决这个问题吗?我也在寻找解决方案。
  • @OwaisKiani 您可以查看下面 Howard E 的回答并确认?我还不能检查它

标签: wordpress woocommerce hook


【解决方案1】:

要移除非静态方法,你应该实例化类,并移除wp_headhttps://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' ) );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多