1
私が見たすべての例は、私がやっていることを正確に行っているように見えます。私は、私のadd_action('init')
フックは発砲していません。WooCommerceの支払いクラス:initフックが__constructで起動されていない
最小、最も簡潔な例では、私の支払いゲートウェイプラグインは次のようになります。
function vnmTestPay_init() {
if (!class_exists('WC_Payment_Gateway')) {
return;
}
class WC_Gateway_Test_Gateway extends WC_Payment_Gateway {
public function init() {
$class = __CLASS__;
new $class;
}
public function __construct() {
add_action('init', array($this, 'process_web_hooks'));
}
public static function process_web_hooks() {
if (!is_admin()) {
// In reality, process some $_GET vars and JSON, but for testing...
die('INIT!');
}
}
}
// Add the gateway to WC
add_filter('woocommerce_payment_gateways', 'vnmTestPay_addGateway');
}
add_action('plugins_loaded', 'vnmTestPay_init', 0);
// Add the Gateway to WooCommerce
function vnmTestPay_addGateway($methods) {
if (!in_array('WC_Gateway_Test_Gateway', $methods)) {
$methods[] = 'WC_Gateway_Test_Gateway';
}
return $methods;
}
私はWPのinit
にフックしたいので、私は期待$_GET
パラメータとのJSON本体と(入ってくるウェブフックを処理することができますコード)を送付します。この例では、ちょうどdie()
を投げたので、私はサイトのホームページを訪れたときに動作することがわかりましたが、サイコロはありませんでした。実際
add_action('plugins_loaded', array('WC_Gateway_Test_Gateway', 'init'));
...:
は、私はクラスをインスタンス化した後、私はこのラインで投げた、のでトリガーinit
フック正しくしかなかった
鉱山の古い支払いプラグインでこれをベースいくつかのフックが2回トリガーされました。だから私はこれがではなく、であると思います。 私はどこに踏み切っているのですか?