Skip to content

Commit

Permalink
Merge pull request #816 from kprajapatii/master
Browse files Browse the repository at this point in the history
enhance renew function to set expiration
  • Loading branch information
kprajapatii authored Nov 25, 2024
2 parents 0af19bd + cf95b06 commit be785a8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions includes/wpinv-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,20 +988,24 @@ public function create_payment( $save = true ) {
* @since 1.0.0
* @return int The subscription's id
*/
public function renew( $calculate_from = null ) {

public function renew( $calculate_from = null, $_new_expiration = null ) {
// Complete subscription if applicable
if ( $this->is_last_renewal() ) {
return $this->complete();
}

// Calculate new expiration
$frequency = $this->get_frequency();
$period = $this->get_period();
$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
if ( ! empty( $_new_expiration ) ) {
$new_expiration = $_new_expiration;
} else {
// Calculate new expiration
$frequency = $this->get_frequency();
$period = $this->get_period();
$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
$new_expiration = date( 'Y-m-d H:i:s', $new_expiration );
}

$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
$this->set_expiration( $new_expiration );
$this->set_status( 'active' );
$this->save();

Expand Down

0 comments on commit be785a8

Please sign in to comment.