admin管理员组

文章数量:1193366

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);

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);
Share Improve this question edited Feb 17, 2021 at 10:14 Rup 4,3904 gold badges28 silver badges29 bronze badges asked Feb 17, 2021 at 5:52 deepsinghdeepsingh 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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');

}

本文标签: