uo_course_grid_after_course_info_holder
Fires after course information is displayed in the course grid, allowing custom content insertion.
add_action( 'uo_course_grid_after_course_info_holder', $callback, 10, 1 );
Description
Fires after the course information holder in the course grid template. Developers can use this hook to add custom content or modify elements following the standard course details, such as pricing, status, or meta information, before the closing anchor tag.
Usage
add_action( 'uo_course_grid_after_course_info_holder', 'your_function_name', 10, 1 );
Parameters
-
$course(mixed) - This parameter holds the current course object being displayed in the grid.
Examples
<?php
/**
* Example function to hook into uo_course_grid_after_course_info_holder.
* This function adds a custom "Enroll Now" button to the course grid if the course
* is not yet completed and is not a "Coming Soon" course.
*
* @param mixed $course The course object or data passed to the hook.
*/
function my_uncanny_toolkit_add_enroll_button_to_course_grid( $course ) {
// Ensure we have a course object and it's valid.
// The actual type of $course will depend on the theme/plugin providing the hook.
// We'll assume it's a LearnDash Course object for this example.
if ( ! $course || ! ( $course instanceof WP_Post ) ) {
return;
}
// Let's assume $course has properties like 'ID', 'post_title', etc.
// In a real scenario, you'd fetch specific course data if needed.
$course_id = $course->ID;
$course_status_icon = ''; // Placeholder for status icon logic, assuming it's available in context or can be fetched.
// You might need to fetch the percentage or enrollment status here.
$percentage = 0; // Assume not started by default.
// Example: Check if user is enrolled and course progress.
// This logic would be more complex in a real application.
if ( function_exists( 'learndash_is_user_enrolled' ) ) {
if ( ! learndash_is_user_enrolled( $course_id ) ) {
// User is not enrolled.
$percentage = 0;
} else {
// User is enrolled, get progress.
$user_id = get_current_user_id();
if ( $user_id ) {
$user_progress = learndash_get_course_progress( $course_id, $user_id );
if ( $user_progress && isset( $user_progress['percentage'] ) ) {
$percentage = $user_progress['percentage'];
}
}
}
}
// Simulate the 'Coming Soon' check. In a real context, $status_icon might be generated earlier.
$is_coming_soon = ( 'Coming Soon' === $course_status_icon );
// Only display the enroll button if the course is not completed and not coming soon.
if ( $percentage < 100 && ! $is_coming_soon ) {
?>
<div class="my-custom-course-actions">
<a href="<?php echo esc_url( get_permalink( $course_id ) ); ?>" class="my-enroll-button">
<?php
// Dynamically set button text based on enrollment status.
if ( function_exists( 'learndash_is_user_enrolled' ) && learndash_is_user_enrolled( $course_id ) ) {
esc_html_e( 'Continue Course', 'your-text-domain' );
} else {
esc_html_e( 'Enroll Now', 'your-text-domain' );
}
?>
</a>
</div>
<?php
}
}
add_action( 'uo_course_grid_after_course_info_holder', 'my_uncanny_toolkit_add_enroll_button_to_course_grid', 10, 1 );
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/templates/course-grid.php:205
style="visibility: hidden">
</div>
<?php } ?>
</div>
<?php do_action_deprecated( 'uo-course-grid-after-course-info-holder', $course, '3.7.11', 'uo_course_grid_after_course_info_holder' ); ?>
<?php do_action( 'uo_course_grid_after_course_info_holder', $course ); ?>
</a>
<?php
/* translators: LearnDash course title */
if ( sprintf( esc_html__( 'View %s Outline', 'uncanny-pro-toolkit' ), LearnDash_Custom_Label::get_label( 'course' ) ) !== $status_icon && 'Coming Soon' !== $status_icon ) {
if ( ( 'show' === $show_start_button && 0 === $percentage ) || ( 'show' === $show_resume_button && $percentage > 0 && $percentage < 100 ) ) {
?>
<div class="uo-toolkit-grid__course-action">