Answers.Body: <p>I don't know if a template override can do this, but an extension may be a good option. You'll need logic to filter on specific contribution pages or other business rules, but here's the basic idea of hooking into the post process action and moving the contribution from the current contact to the household. Another option to consider may be to automatically credit households for donor gifts so that you can give credit to the household but properly track the donor for tax purposes.</p>
  
  <pre><code>/**
   * Implementation of hook_civicrm_post
   */
  function myextension_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
    if($op == 'create' &amp;&amp; $objectName == 'Contribution') {
  
      $current_contact_id = $objectRef['contact_id'];
  
      $household_id = civicrm_api3('Relationship', 'get', array(
        'sequential' =&gt; 1,
        'relationship_type_id' =&gt; 8,
        'contact_id_a' =&gt; $current_contact_id 
      ));
  
  
  
      $result = civicrm_api3('Contribution', 'create', array(
        'sequential' =&gt; 1,
        'id' =&gt; $objectId,
        'contact_id' =&gt; $household_id['contact_id_b'],
      ));
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-18T03:16:03.693Z
Answers.Text: I added a CMS-agnostic way of getting the contact_id and avoided an endless loop when your hook_post triggers itself!  This does NOT leave a way to give individually though, but that wouldn't be hard to add from here.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-18T12:47:11.223Z
Answers.Text: Thanks for the fixes! I did a quick copy/paste from the developer wiki and then added the API calls, but didn't think about checking the $op. @Jeff, this just a starter; you'll need more business logic to prevent all gifts from going to households like Jon mentioned, only fire when a contact is part of a household, etc.
Answers.UserDisplayName: Nicholai
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-09T03:00:40.873Z
Answers.Text: I had to edit it somewhat... original post edited with my final code.
Answers.UserDisplayName: Jeff Mikels
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-17T18:53:22.867Z
Answers.LastActivityDate: 2015-04-18T03:14:52.697Z
Answers.LastEditDate: 2015-04-18T03:14:52.697Z
Answers.UserDisplayName: Nicholai
Answers.Body: <p>I do something very similar with my church. the actual donation is credited to the individual who made it with a soft credit going to the household. This allows us to do reporting by either household or individual. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-18T02:32:57.390Z
Answers.LastActivityDate: 2015-04-18T02:32:57.390Z
Answers.UserDisplayName: frTommy
Body: <p>I'm using CiviCRM 4.5.8 and am setting it up to handle a three year fundraising campaign for our church.</p>
  
  <p>Our church almost exclusively records donations for Households and not for individuals.</p>
  
  <p>How can I create a Contribution Page that allows a person to make Pledges and Contributions that will be linked to their Household?</p>
  
  <p>I am not afraid of custom coding and am currently planning to write a script that automatically shifts all individual pledges to their related household, but if I do that, I still want the contribution page to work for that person to actually make contributions.</p>
  
  <p>Ideally, I'd just use a template override to inject the contact_id of the user's household if there is one or to use the individual contact_id otherwise, but I need some help on how to do that.</p>
  
  <p>I already am comfortable working with template overrides, but I'm asking if anyone knows which template needs to be overridden to get the contact_id in the correct place.</p>
  
  <p>EDIT: SOLUTION CODE</p>
  
  <pre><code>/**
   * Implements hook_civicrm_post
   */
  function householdcontributions_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
      // the _post hook is called AFTER the object has been written to the database
      // because of that, we need to change the contact_id to the household_contact_id
      // and save
      if($op == 'create' &amp;&amp; $objectName == 'Contribution') {
  
          $current_contact_id = $objectRef-&gt;contact_id;
          $real_id = $current_contact_id;
  
  
          // look for a household associated with this contact
          $result = civicrm_api3('Relationship', 'get', array(
            'sequential' =&gt; 1,
            'relationship_type_id' =&gt; 7,
            'contact_id_a' =&gt; $current_contact_id
          ));
  
  
          // override the contact_id with the newly discovered household id
          if ($result['count'] == 1)
          {
              $household_id = $result['values'][0]['contact_id_b'];
              // $objectRef-&gt;contact_id = $household['values'][0]['contact_id_b'];
              $result = civicrm_api3('Contribution', 'create', array(
                'sequential' =&gt; 1,
                'id' =&gt; $objectId,
                'contact_id' =&gt; $household_id,
              ));
          }
      }
  }
  </code></pre>
  
Tags: <contributions><custom-templates><contribution-page><households><pledges>
Title: How do I create contribution pages that record pledges and contributions to households?
ThreadText: # How do I create contribution pages that record pledges and contributions to households?
  
  (Asked by: username_0 on 2015-04-17)
  
  I'm using CiviCRM 4.5.8 and am setting it up to handle a three year fundraising campaign for our church.
  
  Our church almost exclusively records donations for Households and not for individuals.
  
  How can I create a Contribution Page that allows a person to make Pledges and Contributions that will be linked to their Household?
  
  I am not afraid of custom coding and am currently planning to write a script that automatically shifts all individual pledges to their related household, but if I do that, I still want the contribution page to work for that person to actually make contributions.
  
  Ideally, I'd just use a template override to inject the contact\_id of the user's household if there is one or to use the individual contact\_id otherwise, but I need some help on how to do that.
  
  I already am comfortable working with template overrides, but I'm asking if anyone knows which template needs to be overridden to get the contact\_id in the correct place.
  
  EDIT: SOLUTION CODE
  
  ```
  /**
   * Implements hook_civicrm_post
   */
  function householdcontributions_civicrm_post($op, $objectName, $objectId, &$objectRef) {
      // the _post hook is called AFTER the object has been written to the database
      // because of that, we need to change the contact_id to the household_contact_id
      // and save
      if($op == 'create' && $objectName == 'Contribution') {
  
          $current_contact_id = $objectRef->contact_id;
          $real_id = $current_contact_id;
  
          // look for a household associated with this contact
          $result = civicrm_api3('Relationship', 'get', array(
            'sequential' => 1,
            'relationship_type_id' => 7,
            'contact_id_a' => $current_contact_id
          ));
  
          // override the contact_id with the newly discovered household id
          if ($result['count'] == 1)
          {
              $household_id = $result['values'][0]['contact_id_b'];
              // $objectRef->contact_id = $household['values'][0]['contact_id_b'];
              $result = civicrm_api3('Contribution', 'create', array(
                'sequential' => 1,
                'id' => $objectId,
                'contact_id' => $household_id,
              ));
          }
      }
  }
  
  ```
  
  **Tags:** contributions, custom-templates, contribution-page, households, pledges
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-04-17. Score: 1 | Accepted answer
  
  I don't know if a template override can do this, but an extension may be a good option. You'll need logic to filter on specific contribution pages or other business rules, but here's the basic idea of hooking into the post process action and moving the contribution from the current contact to the household. Another option to consider may be to automatically credit households for donor gifts so that you can give credit to the household but properly track the donor for tax purposes.
  
  ```
  /**
   * Implementation of hook_civicrm_post
   */
  function myextension_civicrm_post($op, $objectName, $objectId, &$objectRef) {
    if($op == 'create' && $objectName == 'Contribution') {
  
      $current_contact_id = $objectRef['contact_id'];
  
      $household_id = civicrm_api3('Relationship', 'get', array(
        'sequential' => 1,
        'relationship_type_id' => 8,
        'contact_id_a' => $current_contact_id 
      ));
  
      $result = civicrm_api3('Contribution', 'create', array(
        'sequential' => 1,
        'id' => $objectId,
        'contact_id' => $household_id['contact_id_b'],
      ));
    }
  }
  
  ```
  
  > **Comments:**
  > **username_2**: I added a CMS-agnostic way of getting the contact_id and avoided an endless loop when your hook_post triggers itself!  This does NOT leave a way to give individually though, but that wouldn't be hard to add from here.  
  > **username_1**: Thanks for the fixes! I did a quick copy/paste from the developer wiki and then added the API calls, but didn't think about checking the $op. @username_0, this just a starter; you'll need more business logic to prevent all gifts from going to households like Jon mentioned, only fire when a contact is part of a household, etc.  
  > **username_0**: I had to edit it somewhat... original post edited with my final code.  
  
  ---
  
  ### Answer by username_3 on 2015-04-18. Score: 2
  
  I do something very similar with my church. the actual donation is credited to the individual who made it with a soft credit going to the household. This allows us to do reporting by either household or individual.
  
  
  ---
  
  