2017-12-13 5 views
0

WooCommerceサブスクリプションが新しいサブスクリプション更新オーダーを作成するときに関数を実行しようとしています。WooCommerceサブスクリプション2.0 - wcs_renewal_order_createdアクション/フィルターがエラーをスローする

このイベントをトラップし、詳細を別のデータベースに渡し、バックエンドシステム内で支払いゲートウェイでビジネスワークフローをトリガーできるようにするためです。

私はwcs_renewal_order_createdを使用してadd_actionとadd_filterを試してから、親サブスクリプション注文から手動で更新を作成してこれをテストしました。

フックは関数を呼び出し、コードを実行し、いくつかのデータをいくつかのテストテーブルに入れ、Wordpressは以下のようにエラーを表示します。

更新購読注文が作成されたときに関数をトリガーする簡単な方法はありますか?そうでない場合は、支払い方法を設定しているようなクラスを呼び出すことができないように思われる理由を助けてください。

function log_renewal_order_interface($order, $subscription) { 
write_log('woocommerce_subscriptions_renewal_order_created function called'); 

global $conn; 
global $wpdb, $table_prefix; 

write_log('woocommerce_subscriptions_renewal_order_created setting up test variables'); 

write_log($order); 


$test1 = 'logged renewal order'; 
$test2 = 'order_id'.$order_id; 
$test3 = 'not set'; 
$test4 = 'not set'; 
$test5 = 'not set'; 

// test table entry 
$conn->insert('test_tabel', 
    array('test1' => $test1, 'test2' => $test2, 'test3' => $test3, 'test4' => $test4, 'test5' => $test5), 
    array('%s', '%s', '%s', '%s', '%s')); 

} 

add_filter ('wcs_renewal_order_created', 'log_renewal_order_interface', 10,2); 

は、私は次のエラーを取得:

Fatal error: Uncaught Error: Call to a member function set_payment_method() on null in /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php:176 Stack trace: #0 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286): WCS_Admin_Meta_Boxes::create_pending_renewal_action_request(Object(WC_Subscription)) #1 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php(131): do_action('woocommerce_ord...', Object(WC_Subscription)) #4 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286): WC_Meta_Box_Order_Actions::save(812, Object(WP_Post)) #5 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp- in /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php on line 176

答えて

0

はそれを考え出しました。関数の終わりに$ objectを明示的に返す必要がありました。

関連する問題