' => '', ]; $callback = [ 'class' => get_class( $this ), 'method' => 'render_courses', ]; $args = [ 'id_url' => 'course-related', 'course_id' => $course->get_id(), 'limit' => $limit, ]; $content = TemplateAJAX::load_content_via_ajax( $args, $callback ); echo Template::instance()->nest_elements( $html_wrapper, $content ); } /** * Render template list courses with settings param. * * @param array $settings * * @return stdClass { content: string_html } * @since 4.2.7 * @version 1.0.3 */ public static function render_courses( array $settings = [] ): stdClass { $content = new stdClass(); $content->content = ''; $filter = new LP_Course_Filter(); $course_id = $settings['course_id'] ?? 0; if ( empty( $course_id ) ) { return $content; } $courseModelCurrent = CourseModel::find( $course_id, true ); $terms = $courseModelCurrent->get_categories(); $term_ids = []; foreach ( $terms as $term ) { $term_ids[] = $term->term_id ?? 0; if ( $term->parent ) { $term_ids[] = $term->parent; } } $total_rows = 0; $filter->only_fields = [ 'DISTINCT(ID) AS ID' ]; $filter->post_status = [ 'publish' ]; $filter->limit = $settings['limit'] ?? 4; $filter->term_ids = $term_ids; $filter->query_count = false; $filter->order_by = 'rand()'; $filter->where[] = LP_Database::getInstance()->wpdb->prepare( 'AND p.ID != %d', $course_id ); $courses = Courses::get_courses( $filter, $total_rows ); if ( empty( $courses ) ) { return $content; } // Handle layout $html_ul_courses = [ '', ]; ob_start(); foreach ( $courses as $courseObj ) { $courseModel = CourseModel::find( $courseObj->ID, true ); if ( ! $courseModel instanceof CourseModel ) { continue; } echo ListCoursesTemplate::render_course( $courseModel, $settings ); } $html_courses = Template::instance()->nest_elements( $html_ul_courses, ob_get_clean() ); $sections = apply_filters( 'learn-press/list-courses/related/sections', [ 'header' => sprintf( '

%s

', __( 'You might be interested in', 'learnpress' ) ), 'courses' => $html_courses, ], $courseModelCurrent, $courses, $settings ); $content->content = Template::combine_components( $sections ); return $content; } /** * Render single item course * * @param CourseModel $course * @param array $settings * * @return string * @since 4.2.5.8 * @version 1.0.1 */ public static function render_course( CourseModel $course, array $settings = [] ): string { $singleCourseTemplate = SingleCourseTemplate::instance(); try { $top_wrapper = [ '
' => '
', '
' => '
', ]; $img = sprintf( '%s', $course->get_permalink(), $singleCourseTemplate->html_image( $course ) ); $html_top = Template::instance()->nest_elements( $top_wrapper, $img ); // Section main top $section_main_top = [ 'wrapper_start' => '
', 'level' => $singleCourseTemplate->html_level( $course ), 'price' => $singleCourseTemplate->html_price( $course ), 'wrapper_end' => '
', ]; $html_main_top = Template::combine_components( $section_main_top ); // End section main top // Section main bottom $html_count_student = $singleCourseTemplate->html_count_student( $course ); $section_main_bottom = [ 'wrapper_start' => '
', 'students' => $html_count_student, 'lessons' => $singleCourseTemplate->html_count_item( $course, LP_LESSON_CPT ), 'wrapper_end' => '
', ]; $html_main_bottom = Template::combine_components( $section_main_bottom ); // End section main bottom $section_main = apply_filters( 'learn-press/list-courses/related/layout/item/section/bottom', [ 'wrapper_start' => '
', 'top' => $html_main_top, 'category' => $singleCourseTemplate->html_categories( $course ), 'title' => sprintf( '%s', $course->get_permalink(), $singleCourseTemplate->html_title( $course, 'h4' ) ), 'bottom' => $html_main_bottom, 'wrapper_end' => '
', ], $course, $settings ); $html_section_main = Template::combine_components( $section_main ); $section = apply_filters( 'learn-press/list-courses/related/layout/item/section', [ 'wrapper_start' => sprintf( '
  • ', esc_attr( $course->get_id() ) ), 'top' => $html_top, 'bottom' => $html_section_main, 'wrapper_end' => '
  • ', ], $course, $settings ); $html_item = Template::combine_components( $section ); } catch ( Throwable $e ) { $html_item = $e->getMessage(); } return $html_item; } }