I have a page where the membership payment and different contribution amounts are displayed through a price set to collect member dues for one month.

I was using civicrm 4.0.5 previously and now I am using civicrm 4.7.17

Everything worked perfectly fine on civicrm 4.0.5.

However, in civicrm 4.7.17, after the payments are made the Membership expiry dates do not advance.

So I wrote my own code to advance the membership expiry date to the last day of the next month. Here is the code:

//get the membership dates for the cid                                                                                                                                    
  $membership_get_params = array(
    'version' => 3,
    //specify the membership type id                                                                                                                                        
    'membership_type_id' => $membership_type_id,
    'contact_id' => $objectRef->contact_id,
    'filters' => array(
      'is_current' => 1,
  require_once 'api/api.php';
  $membership_get_result = civicrm_api( 'membership','get',$membership_get_params);
  $membership_get_result = $membership_get_result['values'][$membership_get_result['id']];

  // Find date of next month                                                                                                                                                
  $end_date = $membership_get_result['end_date'];
  $end_date_array = explode('-', $end_date);
  $year = $end_date_array[0];
  $month = $end_date_array[1];
  $day = $end_date_array[2];
  if (in_array($objectRef->contribution_page_id, $one_month_contribution_page_ids)) {
    $next_month = $month + 1;

  if ($next_month > 12) {
    $year = $year + 1;
    $next_month = $next_month - 12;// Get next month if payment for member dues goes beyond the current year                                                                
  $date = $year . '-' . $next_month . '-1';
  $next_month_end_date = new DateTime($date);
  $next_month_end_date = $next_month_end_date->format( 'Y-m-t' );

  $excludeIsAdmin = false;

  $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate( $membership_get_result['start_date'], $membership_get_result['end_date'], $membership_get_resul\

t['join_date'], 'today', $excludeIsAdmin );

  // Save expiry date for membership for contact                                                                                                                            
  $membership_create_params = array(
    'id' => $membership_get_result['id'],
    'contact_id' => $objectRef->contact_id,
    'membership_type_id' => $membership_type_id,
    'start_date' => $membership_get_result['start_date'],
    'join_date' => $membership_get_result['join_date'],
    'end_date' => $next_month_end_date,
    'status_id' => $calcStatus['id'],
    'version' => 3,

  Logger::debug_var("membership_create_params", $membership_create_params);

  require_once 'api/api.php';
  $result = civicrm_api( 'membership', 'create', $membership_create_params );

Is this the optimal solution??

If not, please suggest.

Thanks in advance.

  • You haven't said if your Contributions are being set to Completed or not. That would be one reason Memberships don't get renewed. Generally writing your own code to fix something that is known to work in CiviCRM means you are probably doing a workaround for something else that is not configured correctly such as the payment processor sending info back to civi
    – petednz - fuzion
    Apr 7, 2018 at 2:40

1 Answer 1


Have you confirmed that the Scheduled Job which updates Membership Status is enabled. You have made a bit jump in civi versions and I don't think Scheduled Jobs was around in 4.0.x

  • I tried it but it doesn't work that way either. Sep 11, 2017 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.