Hiding comment section on course when not enrolled
Tagged: overview
-
AuthorPosts
-
-
December 17, 2023 at 11:05 PM #949131Viktor KlingbergParticipant
Hi!
I would like to hide the comment section on course when the user is not enrolled in the course.I’ve found the item-comments.php in templates/single-course/ folder and have no problem adding the code if ( is_user_logged_in() ), but what is a equivalent code to chech if the user is enrolled in the course?
Thanks for the help!
Regards,
Viktor -
December 18, 2023 at 9:56 AM #949193LouisaModerator
Dear Viktor Klingberg,
You can add this condition:
if ( ! $user->has_course_status( $course_id, [ LP_COURSE_ENROLLED, LP_COURSE_FINISHED ] )
|| learn_press_get_user_rate( $course_id ) ) {
return;
}Sincerely
======================
ThimPress support team
Louisa
-
January 13, 2024 at 10:45 PM #953986Viktor KlingbergParticipant
Hi,
Finally getting around to fix this.
This is my code:<?php /** * Template for displaying comments of a course item. * * @author ThimPress * @package LearnPress/Templates * @version 4.0.0 */ defined( 'ABSPATH' ) || exit; if ( is_user_logged_in() ) { if ( ! $user->has_course_status( $course_id, [ LP_COURSE_ENROLLED, LP_COURSE_FINISHED ] ) || learn_press_get_user_rate( $course_id ) ) { return; } else { if ( comments_open() || get_comments_number() ) { ?> <div id="learn-press-item-comments"> <div class="learn-press-comments"> <?php add_filter( 'deprecated_file_trigger_error', '__return_false' ); comments_template(); remove_filter( 'deprecated_file_trigger_error', '__return_false' ); ?> </div> </div> <?php } } } ?>
And i get an error:
Fatal error: Uncaught Error: Call to a member function has_course_status() on null in xxx/public_html/wp-content/themes/eduma-child/learnpress-v4/single-course/item-comments.php:13 Stack trace: #0 xxx/public_html/wp-content/plugins/learnpress/inc/lp-template-functions.php(877): include() #1 xxx/public_html/wp-content/plugins/learnpress/inc/templates/class-lp-template-course.php(931): learn_press_get_template(‘single-course/i…’) #2 xxx/public_html/wp-content/plugins/learnpress/templates/single-course/content-item/popup-content.php(17): LP_Template_Course->course_item_comments() #3 xxx/public_html/wp-content/plugins/learnpress/inc/lp-template-functions.php(877): include(‘xxx…’) #4 /xxx/public_html/wp-content/plugins/learnpress/inc/templates/class-lp-template-course.php(491): learn_press_get_template(‘single-course/c…’) #5 xxx/public_html/wp-includes in xxx/public_html/wp-content/themes/eduma-child/learnpress-v4/single-course/item-comments.php on line 13And idea what’s wrong?
-
January 15, 2024 at 8:34 AM #954107LouisaModerator
Dear Viktor Klingberg,
Please review the child theme’s customizations here
/wp-content/themes/eduma-child/learnpress-v4/single-course/item-comments.php Line 13.Sincerely
======================
ThimPress support team
Louisa
-
January 21, 2024 at 9:32 PM #955516Viktor KlingbergParticipant
Hi,
I posted the code that is failing in the last post, i was wondering if you can help me find whats wrong? I can’t find anything.
I’ll paste the code again:<?php /** * Template for displaying comments of a course item. * * @author ThimPress * @package LearnPress/Templates * @version 4.0.0 */ defined( 'ABSPATH' ) || exit; if ( is_user_logged_in() ) { if ( ! $user->has_course_status( $course_id, [ LP_COURSE_ENROLLED, LP_COURSE_FINISHED ] ) || learn_press_get_user_rate( $course_id ) ) { return; } else { if ( comments_open() || get_comments_number() ) { ?> <div id="learn-press-item-comments"> <div class="learn-press-comments"> <?php add_filter( 'deprecated_file_trigger_error', '__return_false' ); comments_template(); remove_filter( 'deprecated_file_trigger_error', '__return_false' ); ?> </div> </div> <?php } } } ?>
-
January 23, 2024 at 9:46 AM #955784LouisaModerator
Hi Viktor Klingberg,
With your problem, we need to access your admin page to check, can you provide me your website URL and your admin account? We will check the problem for you.
Note:
- When submitting your information, please use “access information”, see instruction here https://thimpress.com/knowledge-base/send-sites-access-information/
- And please back up your website before we do anything on your website.
Yours Sincerely,
Louisa
———-
ThimPress Support Team
-
February 4, 2024 at 11:38 PM #958454Viktor KlingbergParticipant
Hi!
Ok, the site is now backed up and ready. I’ve a childtheme activated -
February 5, 2024 at 11:08 AM #958549LouisaModerator
Dear Viktor Klingberg,
This error occurs when you are on which page?
Sincerely
======================
ThimPress support team
Louisa
-
February 5, 2024 at 12:57 PM #958573Viktor KlingbergParticipant
Hi,
There is no actual error but the comments on a online course is visible for non-logged in users and also users that don’t have access to the course. I want the comments on courses to only be visable for the people that actually bought the course.Se adress in access info for an example.
-
February 6, 2024 at 3:10 PM #958831LouisaModerator
Hi Viktor Klingberg,
We don’t have that feature now.
This is a feature you want to develop further so you should use our custom work service for a small fee. You can contact https://thimpress.com/wordpress-theme-customization-services/
Yours Sincerely,
Louisa
-
February 6, 2024 at 5:47 PM #958898Viktor KlingbergParticipant
Ok, but you don’t have an equivalent code to check if the user is enrolled in the course like the code if user is logged in: ‘if ( is_user_logged_in() )’?
I’ve no problem coding it myself but i need a codesnippet to check if the user is enrolled.
You gave me this code but it’s not working for me..
if ( ! $user->has_course_status( $course_id, [ LP_COURSE_ENROLLED, LP_COURSE_FINISHED ] )
|| learn_press_get_user_rate( $course_id ) ) {
return;
} -
February 15, 2024 at 5:10 PM #959831LouisaModerator
Dear Viktor Klingberg,
Please see has_purchased_course() function in wp-content/plugins/learnpress/inc/user/class-lp-user.php line 186.
Sincerely
======================
ThimPress support team
Louisa
-
-
AuthorPosts
You must be logged in to reply to this topic. You can click here