Disable Wocommerce subscription renewal orders

I wrote some code which should disable woocommerce subscription renewal orders, BUT I'm not satisfied by my code. Please, can you help me find a better solution?

I need to prevent woo to not create and save orders to database, On top of that, we use woocommerce stripe integration, so we also need to prevent woo to send request to stripe. We are handle renewal payments by different way.

Right now the code prevents woo to do so, but return error because can't process the order which been deleted.

function jd_disable_renewal_orders( $order, $subscription ) {
   $note = __("Please, delete this order. / Prosím o smazání této objednávky.");
   $order->add_order_note( $note );

   $sub_id = $order->get_meta('_subscription_renewal');
   $subscription = new WC_Subscription($sub_id);
   $subscription->update_status( 'active' );

   wp_delete_post( $order->get_id(), true );

   return false;
}add_action( 'wcs_renewal_order_created', 'jd_disable_renewal_orders', 10, 2 );


Read more here: https://stackoverflow.com/questions/68469636/disable-wocommerce-subscription-renewal-orders

Content Attribution

This content was originally published by user16479100 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: