Hi anamostafa,
Thank you for reaching out!
You can customize the functionality after a user completes a course using the following hook:
do_action( 'learn-press/user-course-finished', $course_id, $this->get_id(), $return );
This hook is located in the file: wp-content/plugins/learnpress/inc/user/abstract-lp-user.php.
Using this hook, you can create your custom function.
This will allow you to execute any actions and retrieve course information upon course completion.
If you need further assistance, feel free to ask!
Best regards,
Brianvu-tp
Thank you for your reply
I used the following action in order to run my custom function but I got a “There has been a critical error on this website” when course completed
Appreciate your advice
add_action('learn-press/user-course-finished', 'my_custom_function', 10, 2)
function my_custom_function($course_id, $user_id, $course_item) {
// do something
}
Hi anamostafa,
Thank you for your response!
From the code you shared, it seems the issue is due to a missing semicolon (;) at the end of the add_action line. The corrected code should be:
add_action('learn-press/user-course-finished', 'my_custom_function', 10, 2);
function my_custom_function($course_id, $user_id, $course_item) {
// do something
}
Please update your code and test again.
If the issue persists, could you enable Debug Log in WordPress? Then, check the debug log file located at wp-content/debug.log to find the specific error message. Share it with us, and we’ll provide further guidance to resolve the issue.
Looking forward to your reply!
Best regards,
Brianvu-tp
Sure the semicolon was already written
The error log show
{main} thrown in /home/themename/public_html/wp-content/themes/hub-child/functions.php
Is there any explanation for this?
Hi anamostafa,
Thank you for your response and the additional details!
Upon reviewing the issue, it appears that the hook learn-press/user-course-finished passes three parameters, but your implementation is only accepting two parameters, which could cause the critical error.
To resolve this, please update your hook implementation to accept all three parameters:
$course_id: The ID of the completed course.
$user_id: The ID of the user who completed the course.
$return: The completion status of the course.
Here’s the corrected code:
add_action('learn-press/user-course-finished', 'my_custom_function', 10, 3); // Note: The third parameter is now added.
function my_custom_function($course_id, $user_id, $return) {
// do something
}
This should handle all the parameters passed by the hook and prevent the critical error.
If you still encounter issues, please double-check that the function is correctly defined and the file doesn’t contain other syntax errors. Let us know if you need further assistance!
Best regards,
Brianvu-tp