Skip to content

Instantly share code, notes, and snippets.

@flyingwebie
Last active May 2, 2022 09:52
Show Gist options
  • Save flyingwebie/d97f26e09cbb788e66b94d61f63d612f to your computer and use it in GitHub Desktop.
Save flyingwebie/d97f26e09cbb788e66b94d61f63d612f to your computer and use it in GitHub Desktop.
Helpful function for MemberPress with Oxygen Builder.
<?php
function mpr_get_expire_date() {
if(is_user_logged_in()){
$user = MeprUtils::get_currentuserinfo();
$subscriptions = $user->active_product_subscriptions('transactions');
if(!empty($subscriptions)) {
foreach($subscriptions as $s){
// Get Today Date
$today = date("d-m-Y");
$today_str = strtotime($today);
// Get Start Date and convert it to string
// At the moment we DO NOT USE THE START DATE
//$start = $s->created_at;
//$start_str = strtotime($start);
// Get Expire Date and convert it to string
$expire = $s->expires_at;
$expire_str = strtotime($expire);
// Get Free Product ID
$free = $s->product_id;
// Check if the TODAY DATE is smaller than EXPIRE DATE
if($today_str <= $expire_str && $free != '261'){
// If it is TRUE it means that the membership is still active
return "mpr-active";
} else {
// If it is FALSE it means that the membership IS NOT active
return "mpr-inactive";
}
}
} else {
return 'mpr-inactive';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment