【问题标题】:WooCommerce Subscriptions 2.0 - wcs_renewal_order_created action/filter throws errorWooCommerce 订阅 2.0 - wcs_renewal_order_created 操作/过滤器抛出错误
【发布时间】:2018-05-27 20:30:22
【问题描述】:

我正在尝试在 WooCommerce 订阅创建新的订阅续订订单时执行一项功能。

原因是我希望捕获此事件并将详细信息传递到不同的数据库,以便我们可以在后端系统中通过支付网关触发业务工作流。

我已经尝试使用 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);

然后我得到以下错误:

致命错误:未捕获错误:调用成员函数 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 堆栈跟踪:#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 在第 176 行

【问题讨论】:

    标签: woocommerce subscriptions renewal


    【解决方案1】:

    想通了。我需要在函数末尾显式返回 $object。

    【讨论】:

      猜你喜欢
      • 2018-09-29
      • 2016-09-27
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      相关资源
      最近更新 更多