function my_extension_update_custom_field($params) { if ($params['event_name'] == 'hook_civicrm_post') { if ($params['hook'] == 'civicrm_contribution_add') { $contribution_id = $params['id']; // get custom field value $custom_field = civicrm_api3('CustomValue', 'get', [ 'entity_id' => $contribution_id, 'entity_table' => 'civicrm_contribution', 'custom_field_id' => 1, ]); // update custom field value civicrm_api3('CustomValue', 'create', [ 'id' => $custom_field['id'], 'entity_id' => $contribution_id, 'entity_table' => 'civicrm_contribution', 'custom_field_id' => 1, 'value' => 'New Value', ]); } } } CRM_Utils_Hook::register('civicrm_post', 'my_extension_update_custom_field');
function my_extension_send_contact_email($params) { if ($params['event_name'] == 'hook_civicrm_post') { if ($params['hook'] == 'civicrm_contact_add') { $contact_id = $params['id']; // get contact fields $contact = civicrm_api3('Contact', 'get', [ 'id' => $contact_id, ]); // send email $mail = CRM_Core_BAO_Mail::create([ 'from' => 'noreply@example.com', 'toName' => $contact['display_name'], 'toEmail' => $contact['email'], 'subject' => 'New Contact', 'text' => 'A new contact has been added.', ]); $mail->send(); } } } CRM_Utils_Hook::register('civicrm_post', 'my_extension_send_contact_email');This example shows how to use the CRM_Utils_Hook post to trigger an action after a new contact is added. In this case, we are sending an email to the new contact with a notification that they have been added. Package library: CiviCRM