CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adjusting membership price in offline form
Pages: [1]

Author Topic: Adjusting membership price in offline form  (Read 443 times)

cray146

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 1
  • CiviCRM version: 4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.3
Adjusting membership price in offline form
February 22, 2013, 11:11:38 am
Hi,

I'm trying to use the hook_civicrm_buildForm hook to adjust the total amount for a certain membership.

Here is the code:

Code: [Select]
function civicrm_abo_civicrm_buildForm($formName, &$form) {
    if ($formName == 'CRM_Member_Form_Membership') {
      if (array_key_exists('membership_id', $form->_defaultValues)) {
        $membershipId = $form->_defaultValues['membership_id'];
        $membershipTypeId = $form->_defaultValues['membership_type_id'][1];
        if ($membershipTypeId == 1) {
          // setting the default end date works ...
          $defaults['end_date'] = "01/01/2015";
          // setting the amount does not work ...
          $defaults['total_amount'] = "1.00";
          $form->setDefaults($defaults);                                                                                                       
        }
      }
    }
  }

Using the code above I'm able to adjust the end date of the membership by passing the new value to setDefaults(). However, this is not working for the amount (in Membership payment and Receipt section of the form). The amount that is displayed is still the amount that is defined in the membership type configuration. Is there a way to adjust the amount dynamically?

thanks,

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adjusting membership price in offline form

This forum was archived on 2017-11-26.