Skip to content

Commit

Permalink
SUP-37085 Fix expiry in isPriceFieldActive + refactor for efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-fj committed Dec 9, 2021
1 parent 3f0e4ff commit b551452
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion civicrm-ux.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: WP CiviCRM UX
* Plugin URI: https://github.com/agileware/wp-civicrm-ux
* Description: A better user experience for integrating WordPress and CiviCRM
* Version: 1.9.2
* Version: 1.9.3
* Requires at least: 5.8
* Requires PHP: 7.4
* Author: Agileware
Expand Down
28 changes: 5 additions & 23 deletions includes/utils/class-civicrm-ux-membership-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,13 @@ static public function getPriceFieldOptionsOfForm( $currentMembershipTypeId, $op
*/
static public function isPriceFieldActive( $priceFieldOption ) {
$currentDate = new DateTime();
$activeOn = ( isset( $priceFieldOption['price_field_id.active_on'] ) ) ? $priceFieldOption['price_field_id.active_on'] : NULL;
$expireOn = ( isset( $priceFieldOption['price_field_id.expire_on'] ) ) ? $priceFieldOption['price_field_id.expire_on'] : NULL;

$isAfterStartDate = FALSE;
$isBeforeEndDate = FALSE;

if ( ! $activeOn ) {
$isAfterStartDate = TRUE;
} else {
$activeOn = DateTime::createFromFormat( 'Y-m-d H:i:s', $activeOn );
if ( $currentDate >= $activeOn ) {
$isAfterStartDate = TRUE;
}
}
$activeOn = $priceFieldOption['price_field_id.active_on'] ?? null;
$expireOn = $priceFieldOption['price_field_id.expire_on'] ?? null;

if ( ! $expireOn ) {
$isBeforeEndDate = TRUE;
} else {
$expireOn = DateTime::createFromFormat( 'Y-m-d H:i:s', $expireOn );
if ( $expireOn <= $expireOn ) {
$isBeforeEndDate = TRUE;
}
}
$isAfterStartDate = ( ! $activeOn ) || ( $currentDate >= DateTime::createFromFormat( 'Y-m-d H:i:s', $activeOn ) );
$isBeforeEndDate = ( ! $expireOn ) || ( $currentDate < DateTime::createFromFormat( 'Y-m-d H:i:s', $expireOn ) );

return ( $isBeforeEndDate && $isAfterStartDate );
return $isBeforeEndDate && $isAfterStartDate;
}

static public function membership_check() {
Expand Down

0 comments on commit b551452

Please sign in to comment.