Action tin-canny-learndash-reporting

tincanny_reporting_course_report_before_end

Fires before the end of the course report, allowing for custom modifications or data manipulation.

add_action( 'tincanny_reporting_course_report_before_end', $callback, 10, 1 );

Description

Fires before the course report tab's closing elements. Allows developers to inject custom content or modify the report structure. Use this to add custom sections, modify the table's footer, or perform cleanup before the report tab is fully rendered.


Usage

add_action( 'tincanny_reporting_course_report_before_end', 'your_function_name', 10, 1 );

Examples

<?php
/**
 * Adds a custom message to the course report before it ends.
 *
 * This function hooks into the 'tincanny_reporting_course_report_before_end' action
 * to display a personalized message based on the user's progress.
 */
function my_custom_course_report_message() {
	// Assuming the course ID and user ID might be available in the global scope or passed implicitly.
	// In a real scenario, you might need to access these through global variables or
	// retrieve them differently based on how the action hook is implemented.
	global $course_id, $user_id;

	if ( ! empty( $course_id ) && ! empty( $user_id ) ) {
		$course_progress = LearnDash_Tasks_User_Course_Progress::get_progress( $user_id, $course_id );
		$percentage_complete = ( $course_progress['completed'] / $course_progress['total'] ) * 100;

		if ( $percentage_complete < 50 ) {
			echo '<p>Keep up the great work on this course! You're making good progress.</p>';
		} elseif ( $percentage_complete < 90 ) {
			echo '<p>You're almost there! Just a few more steps to complete this course.</p>';
		} else {
			echo '<p>Congratulations on completing this course!</p>';
		}
	} else {
		echo '<p>Thank you for reviewing this course report.</p>';
	}
}

// Add the action hook with a priority of 10 and accepting 0 arguments.
// The '0' indicates that this action doesn't expect any arguments to be passed to the callback function.
add_action( 'tincanny_reporting_course_report_before_end', 'my_custom_course_report_message', 10, 0 );
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/reporting/learndash/templates/course-report-tab.php:161

</table>
				</div>
			</div>
		</div>

	</div>

	<?php do_action( 'tincanny_reporting_course_report_before_end' ); ?>

</div>


Scroll to Top