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?