1

I want to get the updated subscription expiration date when a user successfully completes renewal payment or his card gets charged when trial ends. Is there a way to get the updated date in woocommerce_subscription_renewal_payment_complete hook or in any other hook? I need to tell a third party service that subscription has been updated so that it should update its renewal date that code should supply. So for I have come with below code but I am not able get the updated subscription expiration date.

function cp_subscription_updated($subscription,$last_order ){
    //print_R($last_order);
    $last_order->update_status( 'completed' );
    
    
    $sub_date = WC_Subscriptions_Order::get_next_payment_date ( $last_order, $subscription->get_id() );
    update_user_meta($subscription->get_id(),'sub_date',$sub_date);
    $userData= array('subscription_id' => $cp_sub_id ,'increase_date' =>date('m/d/Y',$sub_date));
    reg_api_register($userData,API_ENDPOINT_UPDATE_SUBS);
    return $last_order;
} 

add_action('woocommerce_subscription_renewal_payment_complete','cp_subscription_updated',10,2);

1 Answer 1

2

This one works for me:

add_action( 'woocommerce_subscription_renewal_payment_complete', 'subscription_renewal_payment_complete', 11, 2 );

function subscription_renewal_payment_complete( $subscription, $order ){
    $subscription_id    = $subscription->get_id();
    $order_id           = $order->get_id();
    $billing_email      = $subscription->get_billing_email();
    $next_payment       = $subscription->get_date('next_payment', 'site');

}
1
  • 1
    So the difference is the $subscription->get_date('next_payment', 'site'), which works but WC_Subscriptions_Order::get_next_payment_date doesn't?
    – Rup
    Commented Dec 10, 2021 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.