2017-12-13 10 views
0

WooCommerce 구독으로 새로운 구독 갱신 주문을 만들 때 함수를 실행하려고합니다.WooCommerce Subscriptions 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를 명시 적으로 반환해야했습니다.