我正忙于创建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\');
}
}
以下操作也不起作用:
woocommerce_order_status_changed
woocommerce_order_status_($status)
有人能告诉我我做错了什么吗?这让我抓狂。。。
最合适的回答,由SO网友:shanebp 整理而成
这是:array(&$this, \'create_credit_note\', 10, 2))
应为:array(&$this, \'create_credit_note\'), 10, 2)