Add a Course Curriculum Section to the “Thank You” Page Using Advanced Custom Fields

Requires Event Espresso 4.8

In this tutorial, I show you how to get started with adding course curriculum/downloads to the “Thank You” page after payment.

Adding a downloads section to the “Thank You” page will allow you to add things like course curriculum or allow registrants to download files that are only accessible after they pay for a class or event.

For this particular tutorial, we will be using two different ACF add-ons to add a “Course Curriculum” section and a few courses to the Event Espresso “Thank You” page. So please make sure you have the “ Repeater Field” and “Flexible Content Field” add-ons for ACF installed and ready to go before we start this tutorial.


It is assumed that you are familiar with ACF, are capable of adding new fields to WordPress posts/custom post types, and can add new hooks to your WordPress theme/functions.php. If you are unfamiliar with ACF, please refer to the details and documentation on the Advanced Custom Fields website.

Add a New ACF Field Group for Course Curriculum

  1. acf-ee-add-new-curriculumCreate a new ACF Field Group (WP Admin > Custom Fields > Add New) [screenshot]
  2. Using the screen shot as a guide, add the following fields to the group:
    1. Class Courses (class_courses | Flexible Content)
      Label: Course Material
      Name: course
      Display: Row
      1. Course Name (course_name | text)
      2. Course Description (course_description | textarea)
      3. Course Image (course_image | image)
      4. Course Files (course_files | repeater)
      5. Course File (course_file | File)
  3. Set the “Show this field group if ” setting to “Post Type > is equal to > espresso_events”.
  4. [optional] Change the order, position, and style of the meta box in the EE4 event editor.

Add a Custom Hook

Next we need to add the code that will output the course curriculum. There are actually two options, which I will outline below:

  • Option 1: Child Theme
    Add the following code to the functions.php file in a child theme. For more information about child themes, checkout the WordPress Child Theme Documentation.
  • Option 2: Site-specific Plugin[Recommended] Create a site specific plugin using the code below. For more information about site specific plugins, check out our documentation on the subject.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file

function ee_course_materials_section_thank_you_page( $registration ) {
  if ( $registration instanceof EE_Registration ) {
    if( get_field('class_courses', $registration->event()->ID()) ):
  ?>
    <tr>
      <td colspan="3">
        <div class="course_materials">
        <h3><span class="dashicons  dashicons-download"></span>Download Course Curriculum</h3>
        <?php while(the_flexible_field("class_courses", $registration->event()->ID())): ?>
          <?php if(get_row_layout() == "course"): // layout: Featured Posts ?>
            <div>
              <h2><img align="right" src="<?php the_sub_field( "course_image", $registration->event()->ID() )?>"><?php the_sub_field("course_name", $registration->event()->ID()); ?></h2>
              <?php the_sub_field("course_description", $registration->event()->ID()); ?>
              <?php if(get_sub_field("course_files", $registration->event()->ID())): ?>
                <ul>
                <?php foreach(get_sub_field("course_files", $registration->event()->ID()) as $cf): ?>
                  <li><a href="<?php echo $cf['course_file']['url']; ?>"><?php echo $cf['course_file']['title'];?></a></li>
                <?php endforeach; ?>
                </ul>
              <?php endif; ?>
            </div>
          <?php endif; ?>
        <?php endwhile; ?>
      </td>
    </tr>
    <?php
    endif;
  }
}
add_action( 
  'AHEE__thank_you_page_registration_details_template__after_registration_table_row', 
  'ee_course_materials_section_thank_you_page', 
  10, 
  1 
);
	

Visit the row on Git: https://gist.github.com/joshfeck/eda214fb8c0227690fb797907a046b1d#file-add_course_curriculum_events-php

The snippet above uses an EE4 action hook called

AHEE__thank_you_page_registration_details_template__after_registration_table_row

to display the contents of the
ee_course_materials_section_thank_you_page() function, which contains the HTML for the new section to download the course materials. The data for the ACF fields are pulled from the WP global $post variable.


acf-ee-add-new-curriculum-eventCreate a New Event & Add Course Materials

  1. Create a new Event Espresso event (WP Admin > Event Espresso > Events > Add New Event)
  2. In the new meta box generated by ACF using the steps outlined above, add the course details and files to the event. [screenshot]
  3. Publish the event.

Finishing up the course curriculum section

That covers adding a course curriculum section to a single event on the thank you page. After successfully registering and paying for an event, you should end up with something like this on the payment page:

acf-ee-curriculum-thank-you-page

Related

Adding Related Events Using Advanced Custom Fields

Add a Sponsors Section to Events Using Advanced Custom Fields

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us