WooCommerce:一些动作钩子在类内未触发

时间:2017-02-19 作者:Wikus

我正忙于创建WooCommerce的集成。我注意到有些钩子能用,而有些钩子不行。为什么会这样?我的代码类似于以下代码(我删除了与我的问题无关的所有内容):

class WC_Integration_Sage_One_Integration extends WC_Integration {

public static function instance() {    

    return new self(); 

}

public function __construct() {
    // This WORKS
    add_action(\'woocommerce_checkout_order_processed\', array( &$this, \'create_invoice\'), 10, 1);

    // This DOES NOT WORK
    add_action( \'woocommerce_order_refunded\', array(&$this, \'create_credit_note\', 10, 2));
}

public function create_invoice($order_id) {
    // Test if hook fires. (It does and mail is sent)
    wp_mail(\'[email protected]\', \'Test\', \'Test if hook fires\');
}

public function create_credit_note($order_id, $refund_id) {
    // Test if hook fires. (It DOES NOT and no mail is sent)
    wp_mail(\'[email protected]\', \'Test\', \'Test if hook fires\');
}

}
以下操作也不起作用:

  1. woocommerce_order_status_changed

  2. woocommerce_order_status_($status)

1 个回复
最合适的回答,由SO网友:shanebp 整理而成

这是:array(&$this, \'create_credit_note\', 10, 2))

应为:array(&$this, \'create_credit_note\'), 10, 2)

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register