当WooCommerce订阅创建新的订阅更新顺序时,我试图执行一个函数。
原因是我希望捕捉这个事件,并将详细信息传递到一个不同的数据库,这样我们就可以在后端系统中用我们的支付网关触发业务工作流。
我尝试过使用add_action和add_filter使用wcs_renewal_order_created,然后通过从父订阅订单手动创建更新付款来测试这一点。
钩子调用函数,执行代码,将一些数据放入一些测试表中,然后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);然后,我得到以下错误:
致命错误:未捕获错误:调用/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php:176堆栈跟踪中null上的成员函数set_payment_method():#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->应用_过滤器(‘’,数组) #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.’,对象( /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286):(WC_Subscription)) #4 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php WC_Meta_Box_Order_Actions::save(812,Object(WP_Post)) #5
发布于 2017-12-14 07:08:12
弄明白了。我需要在函数的末尾显式返回$object。
https://stackoverflow.com/questions/47801689
复制相似问题