0
votes

I am trying to execute a function when WooCommerce subscriptions creates a new subscription renewal order.

The reason being I wish to trap this event and pass details to a different database so we can trigger business workflows with our payment gateway, within our backend systems.

I've tried add_action and add_filter using wcs_renewal_order_created and then tested this by manually creating a renewal payment from the parent subscription order.

The hook calls the function, executes the code, puts some data into some test tables and then Wordpress shows an error as shown below.

Is there a simpler way to trigger a function when a renewal subscription order is created and if not, can anyone help as to why it seems to be failing calling a class that seems to set the payment method.

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);

I then get the following error:

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

1

1 Answers

0
votes

Figured it out. I needed to explicitly return $object at the end of the function.