I’m using the Woocommerce Subscriptions plugin, and in the processing order renewal email I wanted to show when the next payment date will be. However when I try to access the next payment date for an order it always returns false.
<?php
if (WC_Subscriptions_Renewal_Order::is_renewal( $order ) ) { /* This returns true */
$parent_id = WC_Subscriptions_Renewal_Order::get_parent_order_id( $order ); /* This gets the original parent order id */
$parent_order = new WC_Order( $parent_id );
foreach ($parent_order->get_items() as $item) { /* This loops through each item in the order */
$h = WC_Subscriptions_Order::get_next_payment_date ( $parent_order, $item['product_id'] ); /* This should get the next payment date... */
var_dump($h); /* But it returns false :-( */
}
}
?>
Other functions such as WC_Subscriptions_Order::get_total_initial_payment()
work as expected.
How can I get the next payment date for a subscription order?
I figured it out – looks like I was working an order where the subscription had been cancelled, hence
get_next_payment_date()
returning false.Here is my solution if it helps anyone else trying to do a similar thing:
You can also get next payment date for a subscription using below code