Custom Hook causes for a PCP problems on event registration page
The problem is that your hook is executing unconditionally on every form. To target just the contribution form, the first line inside your function should be if ($formName == 'CRM_Contribute_Form_Contribution_Main') {.