Tutor LMS: CSS Classes Based on the Student's Course Status
Adds body classes such as wpide-tutor-enrolled or wpide-tutor-completed on Tutor LMS course pages, so you can show or hide elements with CSS.
Opens WPIDE on
Code
if ( ! function_exists( 'tutor_utils' ) ) {
return;
}
add_filter( 'body_class', function ( $classes ) {
if ( ! is_singular( tutor()->course_post_type ) ) {
return $classes;
}
$course_id = get_queried_object_id();
$user_id = get_current_user_id();
if ( ! $user_id ) {
$classes[] = 'wpide-tutor-guest';
} elseif ( ! tutor_utils()->is_enrolled( $course_id, $user_id ) ) {
$classes[] = 'wpide-tutor-not-enrolled';
} else {
$classes[] = 'wpide-tutor-enrolled';
if ( tutor_utils()->is_completed_course( $course_id, $user_id ) ) {
$classes[] = 'wpide-tutor-completed';
}
}
return $classes;
} );
Notes
Classes: wpide-tutor-guest, wpide-tutor-not-enrolled, wpide-tutor-enrolled, wpide-tutor-completed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.