Answers.Body: <p>the following did the trick - works in this situation well enough as we only allow registering one participant:</p>
  
  <pre><code>{$participantIDs.0}
  </code></pre>
  
  <p>The above grabs the participant ID of the first (and only in our case) participant</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-24T22:16:05.153Z
Answers.Text: I found a PHP-only approach to get the participant_id. @ me if interested.
Answers.UserDisplayName: dsmith63
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-09T17:06:45.247Z
Answers.Text: @dsmith63 sure thing - please do share. Thanks!
Answers.UserDisplayName: MtnPavlas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-09T03:27:12.920Z
Answers.LastActivityDate: 2018-04-09T03:27:12.920Z
Answers.UserDisplayName: MtnPavlas
Answers.Body: <p>The participant_id can be accessed on the event registration thank you page in two different ways -- by using Smarty template variables when the user is logged in or by using session variables when the user is anonymous. Both approaches work when used inside the &quot;civicrmBuildForm&quot; hook.</p>
  <p><strong>1) User logged in</strong></p>
  <pre><code>add_action( 'civicrm_buildForm', 'getParticipantId' );
  
  function getParticipantId() {
      $template = (array) CRM_Core_Smarty::singleton();
      $event = $template['_tpl_vars']['event'];
  
      $participant = civicrm_api3('Participant', 'getsingle', [
          'sequential' =&gt; 1,
          'contact_id' =&gt; &quot;user_contact_id&quot;,
          'event_id' =&gt; $event['id'],
      ]);
  
      echo $participant['id'];
  }
  </code></pre>
  <p><strong>2) Anonymous user</strong></p>
  <pre><code>add_action( 'civicrm_buildForm', 'getParticipantId' );
  
  function getCrmFromSession($session) {
      if (!empty($session)) {
          $seshAry = (array) $session;
          $seshKey = array_keys($seshAry)[1];
          $CiviCRM = json_decode(json_encode($seshAry[$seshKey]), true)['CiviCRM'];
  
          if ( !empty($CiviCRM['CRM_Utils_Recent']) &amp;&amp; isset($CiviCRM['CRM_Utils_Recent'][0]['id']) ) {
              $CiviCRM['participant_id'] = $CiviCRM['CRM_Utils_Recent'][0]['id'];
          }
  
          return $CiviCRM;
      } else {
          return array();
      }
  }
  
  function getParticipantId() {
      $CiviCRM = getCrmFromSession(CRM_Core_Session::singleton());
  
      echo $CiviCRM['participant_id'];
  }
  </code></pre>
  <ul>
  <li>I appended a template to the Thank You template with the data related to participant_id.</li>
  <li>In my case, the BuildForm hook lives in my theme's functions.php file.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-10T18:46:05.843Z
Answers.Text: @MtnPavlas, hope this helps.
Answers.UserDisplayName: dsmith63
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-11T01:48:30.667Z
Answers.Text: thank you for the code, @dsmith63 - super helpful
Answers.UserDisplayName: MtnPavlas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-10T18:45:47.660Z
Answers.LastActivityDate: 2022-02-10T18:45:47.660Z
Answers.UserDisplayName: dsmith63
Body: <p>How could I get the participant ID and the corresponding contact ID on the event registration thank-you page? E.g. is there a field (or piece of code) I can insert in /templates/CRM/Event/Form/Registration/DisplayProfile.tpl ?</p>
  
  <p>For participant ID I tried the following but to no avail:</p>
  
  <pre><code>&lt;div class="participant-id hidden"&gt;{$participant.id}&lt;/div&gt;
  </code></pre>
  
  <p>Thank you for any tips</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-08T06:18:16.170Z
Comments.Text: you can try inserting `{debug}` at any line in the file and check the variables that are populating for the template file.
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-09T03:17:22.660Z
Comments.Text: Thank you for the tip, @jitendra-fuzion, I did what you suggested, and the only helpful variable I see is an array {$participantIDs} ... we only allow one participant so how could I grab the first (and only) item in the array?
Comments.UserDisplayName: MtnPavlas
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-09T03:25:27.763Z
Comments.Text: OK - found a good-enough answer for now - posting it below; thank you again for the tip
Comments.UserDisplayName: MtnPavlas
Tags: <registration><online-registration><participants>
Title: how to get participant id on registration thank-you page
ThreadText: # how to get participant id on registration thank-you page
  
  (Asked by: username_0 on 2018-04-08)
  
  How could I get the participant ID and the corresponding contact ID on the event registration thank-you page? E.g. is there a field (or piece of code) I can insert in /templates/CRM/Event/Form/Registration/DisplayProfile.tpl ?
  For participant ID I tried the following but to no avail:
  {$participant.id}
  
  Thank you for any tips
  
  **Tags:** registration, online-registration, participants
  
  > **Comments:**
  > **username_1**: you can try inserting `{debug}` at any line in the file and check the variables that are populating for the template file.  
  > **username_0**: Thank you for the tip, @jitendra-fuzion, I did what you suggested, and the only helpful variable I see is an array {$participantIDs} ... we only allow one participant so how could I grab the first (and only) item in the array?  
  > **username_0**: OK - found a good-enough answer for now - posting it below; thank you again for the tip  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-04-09. Score: 3
  
  the following did the trick - works in this situation well enough as we only allow registering one participant:
  {$participantIDs.0}
  
  The above grabs the participant ID of the first (and only in our case) participant
  
  > **Comments:**
  > **username_2**: I found a PHP-only approach to get the participant_id. @ me if interested.  
  > **username_0**: @username_2 sure thing - please do share. Thanks!  
  
  ---
  
  ### Answer by username_2 on 2022-02-10. Score: 2
  
  The participant_id can be accessed on the event registration thank you page in two different ways -- by using Smarty template variables when the user is logged in or by using session variables when the user is anonymous. Both approaches work when used inside the "civicrmBuildForm" hook.
  1) User logged in
  add_action( 'civicrm_buildForm', 'getParticipantId' );
  
  function getParticipantId() {
      $template = (array) CRM_Core_Smarty::singleton();
      $event = $template['_tpl_vars']['event'];
  
      $participant = civicrm_api3('Participant', 'getsingle', [
          'sequential' => 1,
          'contact_id' => "user_contact_id",
          'event_id' => $event['id'],
      ]);
  
      echo $participant['id'];
  }
  
  2) Anonymous user
  add_action( 'civicrm_buildForm', 'getParticipantId' );
  
  function getCrmFromSession($session) {
      if (!empty($session)) {
          $seshAry = (array) $session;
          $seshKey = array_keys($seshAry)[1];
          $CiviCRM = json_decode(json_encode($seshAry[$seshKey]), true)['CiviCRM'];
  
          if ( !empty($CiviCRM['CRM_Utils_Recent']) && isset($CiviCRM['CRM_Utils_Recent'][0]['id']) ) {
              $CiviCRM['participant_id'] = $CiviCRM['CRM_Utils_Recent'][0]['id'];
          }
  
          return $CiviCRM;
      } else {
          return array();
      }
  }
  
  function getParticipantId() {
      $CiviCRM = getCrmFromSession(CRM_Core_Session::singleton());
  
      echo $CiviCRM['participant_id'];
  }
  
  
  I appended a template to the Thank You template with the data related to participant_id.
  In my case, the BuildForm hook lives in my theme's functions.php file.
  
  > **Comments:**
  > **username_2**: @username_0, hope this helps.  
  > **username_0**: thank you for the code, @username_2 - super helpful  
  
  ---
  
  