0

I have been using this code to process a renewal payment. The problem is that this line

 $parent_id                  = WC_Subscriptions_Renewal_Order::get_parent_order_id( $subscription ); // <<<<< this is failing

Ultimately causes a fatal error:

 Fatal error: Uncaught Error: Call to a member function get_parent_id() on null in ....public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-renewal-order.php:315

Presently my code is this:

 add_action( 'woocommerce_subscription_renewal_payment_complete', 'mmd_woocommerce_subscription_renewal_payment_complete', 1, 2);      // The subscription renewal payment
 function mmd_woocommerce_subscription_renewal_payment_complete($subscription, $last_order)
 {
 global $wpdb;

 $SubscriptionNumber         = $subscription->get_order_number();
 $BusinessEmail              = $subscription->get_billing_email();

 $OrderNumber                = $subscription->parent_id;

 //***********************************
 // Another way to get the Parent Order from the subscription.
 $parent_id                  = WC_Subscriptions_Renewal_Order::get_parent_order_id( $subscription ); // <<<<< this is failing
 $ParentOrder                = new WC_Order( $parent_id );
//***********************************


 foreach ( $subscription->get_items() as $item ) 
   { 
   $NewExpiration = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $item['product_id'] ); /* This should get the next payment date... */
   if ( $NewExpiration )
      {
      Do some work...
      }
  }
 }

I need another way to get the Parent Order Id. Any ideas?

Debbie Kurth
  • 403
  • 3
  • 16

1 Answers1

0

Hi @Debbie Kurth -- you asked your question quite a while ago so maybe this is moot, but perhaps someone else with the same question will land here.

WooCommerce no longer allows certain order properties to be accessed directly, so you need to use the relevant get_something() functions instead.

e.g., instead of $OrderNumber = $subscription->parent_id;

use: $OrderNumber = $subscription->get_parent_id();

See also https://stackoverflow.com/a/44822414

codebird
  • 357
  • 7
  • 17