【问题标题】:Calling a add_filter inside a Wordpress class在 Wordpress 类中调用 add_filter
【发布时间】:2019-12-25 10:15:03
【问题描述】:

我试图在 Wordpress 类中调用这个 add_filter。我遵守了所有规则,但由于某种原因,它不起作用。

class WoocommerceController extends BaseController
{

function register(){
   add_filter('woocommerce_thankyou_order_received_text', array($this, 'woo_change_order_received_text', 10, 2 ));
    }
function woo_change_order_received_text( $str, $order ) {
    $new_str = $str . ' We have emailed the purchase receipt to you.';
    return $new_str;
   }
}

【问题讨论】:

  • 你是如何尝试执行这段代码的?
  • @Dmitry 那是什么意思?这个类由另一个类初始化。所有 add_action 函数都可以工作,但 add_filter 永远不会工作
  • 所以你正在编辑这个课程?

标签: php wordpress class woocommerce add-filter


【解决方案1】:

您在数组中传递优先级和参数,这就是它不起作用的原因 add_filter('woocommerce_thankyou_order_received_text', 数组($this, 'woo_change_order_received_text'), 10, 2) 这样写

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-05
    • 2016-12-12
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多