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.
Add a New ACF Field Group for Course Curriculum
- Create a new ACF Field Group (WP Admin > Custom Fields > Add New) [screenshot]
- Using the screen shot as a guide, add the following fields to the group:
- Class Courses (class_courses | Flexible Content)
Label: Course Material
Name: course
Display: Row- Course Name (course_name | text)
- Course Description (course_description | textarea)
- Course Image (course_image | image)
- Course Files (course_files | repeater)
- Course File (course_file | File)
- Class Courses (class_courses | Flexible Content)
- Set the “Show this field group if ” setting to “Post Type > is equal to > espresso_events”.
- [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.
Create a New Event & Add Course Materials
- Create a new Event Espresso event (WP Admin > Event Espresso > Events > Add New Event)
- In the new meta box generated by ACF using the steps outlined above, add the course details and files to the event. [screenshot]
- 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:
Related
Adding Related Events Using Advanced Custom Fields
Add a Sponsors Section to Events Using Advanced Custom Fields