Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Order::calculate_next_payment_date( string $format = 'Y-m-d H:i:s' )
Calculate the next payment due date
Parameters Parameters
- $format
-
(string) (Optional) PHP date format used to format the returned date string.
Default value: 'Y-m-d H:i:s'
Return Return
(string) The formatted next payment due date or an empty string when there is no next payment.
Source Source
File: includes/models/model.llms.order.php
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | private function calculate_next_payment_date( $format = 'Y-m-d H:i:s' ) { // If the limited plan has already ended return early. $remaining = $this ->get_remaining_payments(); if ( 0 === $remaining ) { // This filter is documented below. return apply_filters( 'llms_order_calculate_next_payment_date' , '' , $format , $this ); } $start_time = $this ->get_date( 'date' , 'U' ); $next_payment_time = $this ->get_date( 'date_next_payment' , 'U' ); $last_txn_time = $this ->get_last_transaction_date( 'llms-txn-succeeded' , 'recurring' , 'U' ); // If were on a trial and the trial hasn't ended yet next payment date is the date the trial ends. if ( $this ->has_trial() && ! $this ->has_trial_ended() ) { $next_payment_time = $this ->get_trial_end_date( 'U' ); } else { /** * Calculate next payment date from the saved `date_next_payment` calculated during * the previous recurring transaction or during order initialization. * * This condition will be encountered during the 2nd, 3rd, 4th, etc... recurring payments. */ if ( $next_payment_time && $next_payment_time < llms_current_time( 'timestamp' ) ) { $from_time = $next_payment_time ; /** * Use the order's last successful transaction date. * * This will be encountered when any amount of "chaos" is * introduced causing the previously stored `date_next_payment` * to be GREATER than the current time. * * Orders created */ } elseif ( $last_txn_time && $last_txn_time > $start_time ) { $from_time = $last_txn_time ; /** * Use the order's creation time. * * This condition will be encountered for the 1st recurring payment only. */ } else { $from_time = $start_time ; } $period = $this ->get( 'billing_period' ); $frequency = $this ->get( 'billing_frequency' ); $next_payment_time = strtotime ( '+' . $frequency . ' ' . $period , $from_time ); /** * Make sure the next payment is more than 2 hours in the future * * This ensures changes to the site's timezone because of daylight savings * will never cause a 2nd renewal payment to be processed on the same day. */ $i = 1; while ( $next_payment_time < ( llms_current_time( 'timestamp' , true ) + 2 * HOUR_IN_SECONDS ) && $i < 3000 ) { $next_payment_time = strtotime ( '+' . $frequency . ' ' . $period , $next_payment_time ); $i ++; } } /** * Filter the calculated next payment date * * @since 3.10.0 * * @param string $ret The formatted next payment due date or an empty string when there is no next payment. * @param string $format The requested date format. * @param LLMS_Order $order The order object. */ return apply_filters( 'llms_order_calculate_next_payment_date' , date ( $format , $next_payment_time ), $format , $this ); } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.3.0 | Determine if a limited order has ended based on number of remaining payments in favor of current date/time. |
4.9.0 | Fix comparison for PHP8 compat. |
3.37.6 | Now uses the last successful transaction time to calculate from when the previously stored next payment date is in the future. |
3.12.0 | Unknown. |
3.10.0 | Introduced. |