If your courses are closed, then you might see a tool-tip message that reads- You don’t currently have access to this content. The message per se is very fine, but there might be cases when you want to convey a differently worded message to suit your specific purpose.

What is more, there can even be situations where you may require to create different tool-tip messages for different courses depending on the nature and function of the content being transmitted.

With some code work, you can either create a completely uniform tool tip message ( different from the default one ) for all of your courses or you can craft different messages for a variety of different courses, while having a uniform message at the same time for all other remaining courses.

Here is the code to achieve that.

/**
 * Change group course tooltip
 
add_filter( 'learndash_group_course_row_atts', function( $data_tooltip, $course_id, $group_id, $user_id ) {
    if ( 6542 === $course_id && ! empty( $data_tooltip ) ) { // Target course with ID 6542
        $data_tooltip = 'data-ld-tooltip="' . esc_html__( "You don't currently have access to this content", 'learndash' ) . '"';
    }
    return $data_tooltip;
}, 10, 4 );
*/

/**
 * Change non-sample lesson tooltip for specific courses
 */
add_filter( 'learndash_lesson_row_atts', function( $data_tooltip, $lesson_id, $course_id, $user_id ) {
    // Array of course IDs where custom tooltip message should be applied
    $target_course_ids = array( 21089, 6542, 5678 );

    // Check if the current course ID is in the array of target course IDs
    if ( in_array( $course_id, $target_course_ids ) && ! empty( $data_tooltip ) ) {
        // Customize the tooltip message for the specified courses
        $data_tooltip = 'data-ld-tooltip="' . esc_html__( "Tap 'Get for Free' button above to unlock it", 'learndash' ) . '"';
    }
    return $data_tooltip;
}, 10, 4 );

/**
 * Change quiz tooltip
 
add_filter( 'learndash_quiz_row_atts', function( $data_tooltip, $quiz_id, $course_id ) {  // Added $course_id argument
    if ( 6542 === $course_id && ! empty( $data_tooltip ) ) { // Target course with ID 6542
        $data_tooltip = 'data-ld-tooltip="' . esc_html__( "You don't currently have access to this content", 'learndash' ) . '"';
    }
    return $data_tooltip;
}, 10, 3 ); // Adjusted priority and number of arguments
*/

That’s all.

Leave a Reply