I am using WooCommerce Subscriptions with manual payments using the 'bacs' payment method. When recurring orders are created, the code below changes the status from 'Pending' to 'Processing' which keeps the subscription 'Active'. This allows a recurring order to be automatically created every interval regardless of whether the previous order has been marked 'Completed' or not.
add_action('wcs_renewal_order_created', 'sab_auto_complete_renewals_by_payment_method', 10, 2);
function sab_auto_complete_renewals_by_payment_method($order_id)
{
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
if ($order->data['status'] == 'pending') {
$payment_method=$order->get_payment_method();
if ($payment_method!="bacs")
{
$order->update_status( 'processing' );
}
}
}
However, although this works, I am seeing errors logged within WooCommerce.
Error: "scheduled action 26701 (subscription payment) failed to finish processing due to the following error: Uncaught Error: Call to a member function get_total() on bool in /home/sites/13b/6/69781a941d/public_html/contract/sab-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-manager.php:128"
Line 128 (class-wc-subscriptions-manager.php):
if ( 0 == $renewal_order->get_total() ) {
$renewal_order->payment_complete(); // We don't need to reactivate the subscription here because calling payment complete on the order will do that for us.
} else {
if ( $subscription->is_manual() ) {
do_action( 'woocommerce_generated_manual_renewal_order', wcs_get_objects_property( $renewal_order, 'id' ), $subscription );
$renewal_order->add_order_note( __( 'Manual renewal order awaiting customer payment.', 'woocommerce-subscriptions' ) );
} else {
$renewal_order->set_payment_method( wc_get_payment_gateway_by_order( $subscription ) ); // We need to pass the payment gateway instance to be compatible with WC < 3.0, only WC 3.0+ supports passing the string name
if ( is_callable( array( $renewal_order, 'save' ) ) ) { // WC 3.0+ We need to save the payment method.
$renewal_order->save();
}
}
}
} else {
$renewal_order = false;
}
If anyone knows how to prevent this error, any help would be appreciated!
Or if anyone knows how to keep a subscription 'Active' regardless of the order status, please let me know. Ive tried a variety of suggestions, however I am unable to find the right hook for renewals: Auto change Woocommerce Subscriptions status to "On-Hold" rather than "Active"