0

I'm trying to use the hook civicrm_buildForm to modify the contribution value based on specific logic.

I know I can use setDefaults() but I don't know how to get the field ID.

For this contribution form, I'm using a Price set.

Update

I tried this, but it didn't work:

if (isset($form->_priceSet['fields'])) {
    foreach ($form->_priceSet['fields'] as &$field) {
        if ($field['name'] == 'amount') {
            foreach ($field['options'] as &$option) {
                if ($option['label'] == 'Amount') {
                    $option['amount'] = 50;
                }
            }
        }
    }
}

1 Answer 1

0

Would suggest using the hook_civicrm_buildAmount hook as you won't need to handle the amount change at multiple places.

2
  • Thanks @Pradeep Nayak. I tried this but didn't work: add_action('civicrm_buildAmount', function ($pageType, $form, $amount) { $amount[737]['options'][1486]['amount'] = 29; }, 10, 3); Commented May 17 at 14:17
  • did you replace it correctly? Commented May 20 at 8: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.