Coursepress 2.0 update - HTTP 500 Error

Since updating to coursepress 2.0 my site has broken.

Errors
- When a user tries to sign up using woocommerce and stripe, I get the error 'Internal Server Error' within the checkout page.
- When I try to preview the unit pages I get HTTP 500 errors
- Some stand alone pages that we're working fine before now get a 'too many redirects' error.

These are the problems I have found so far.

Things I have tried so far...
- updated all plugins
- deactivated all plugins try look for conflicts
- used the default coursepress theme

Plus followed and completed these support suggestions -
https://premium.wpmudev.org/forums/topic/coursepress-pro-upgraded-to-201-and-now-i-cant-view-cp-pages
https://premium.wpmudev.org/forums/topic/good-day-ive-just
https://premium.wpmudev.org/forums/topic/coursepress-woocommerce-not-working-after-update-26-jan#post-1206345

Help...

  • Tom
    • Site Builder, Child of Zeus

    ** UPDATE **

    I have managed to locate a potential cause of the 'When a user tries to sign up using woocommerce and stripe, I get the error 'Internal Server Error' within the checkout page.' error page. This was actually due to a mu-plugin error. The plugin was created by you guys to force auto enrolment when a user signs up.

    <?php
    
    add_action('user_register', 'wpmudev_enroll_for_all', 20);
    function wpmudev_enroll_for_all($user_id)
    {	
    
        $student = new Student($user_id);
    
        global $wpdb;
        $course_type = 'course';
    
        $courses = $wpdb->get_results(
    	    $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts WHERE post_type='%s' LIMIT 10", $course_type )
    	 );
    
        foreach ($courses as $course) {
            $student->enroll_in_course($course->ID);
        }
    
    }
    ?>

    ** FURTHER UPDATE **

    This does NOT resolve the HTTP 500 error that appears when trying to view course unit on the front end.

    ** YET ANOTHER UPDATE **

    The HTTP 500 error was resolved by switching back to the coursepress theme

  • Rupok
    • Support Ninja

    Hi Tom,

    So sorry to hear the inconvenience you were having. From your updates, it seems like your issues are gone.

    Can you please confirm if we are good now or am I missing any point? Please let us know if you are still facing any issue with this new version. We will be glad to investigate further and will try to resolve those as soon as possible.

    Have a nice day. Cheers!
    Rupok

  • Tom
    • Site Builder, Child of Zeus

    Hi Rupok

    Sadly the issues still remain.

    Some of the issues have been fixed but not all of them.

    The Must Use Plugin created by yourselves that automatically enrolls new users onto the course now creates an internal server error. See screenshot. This is when trying to process an order with woocommerce.

    <?php
    
    add_action('user_register', 'wpmudev_enroll_for_all', 20);
    function wpmudev_enroll_for_all($user_id)
    {	
    
        $student = new Student($user_id);
    
        global $wpdb;
        $course_type = 'course';
    
        $courses = $wpdb->get_results(
    	    $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts WHERE post_type='%s' LIMIT 10", $course_type )
    	 );
    
        foreach ($courses as $course) {
            $student->enroll_in_course($course->ID);
        }
    
    }
    ?>

  • Denitsa
    • WordPress Warrior

    Hello there Tom,
    I hope you're well and i'm sorry for the delay in response on this one!

    Could you please enable WP_DEBUG ?
    Here's a blog post that describes how to do so https://premium.wpmudev.org/blog/debugging-wordpress-how-to-use-wp_debug/

    Then proceed to the page that gives the error.
    The log will be saved to a debug.log file inside the "/wp-content" folder. Please save the file as a .txt and attach it to your next post.

    Can you also please grant support access from the dashboard plugin so we can take a closer look?
    This could be done via Dashboard - WPMU DEV -> Support -> Support Access -> Grant Access or by following this guide here:
    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    I'm looking forward to hearing from you and resolving this issue as soon as possible.

    All the best,
    Denitsa

  • Kasia Swiderska
    • Support nomad

    Hello Tom,

    I'm sorry for the delay! Please check this code:

    <?php
    /**
     * Plugin Name: Enroll new user!
     * Plugin URI: https://premium.wpmudev.org/
     * Description: Enroll new registered user to all available courses. Be careful it can break your site if you have a lot of available courses.
     * Version: 1.0
     * Author: Marcin Pietrzak (Incsub)
     * Author URI: https://premium.wpmudev.org/profile/marcin10
     * License: GPL2+
     */
    
    add_action('user_register', 'coursepress_custom_enroll_for_all');
    
    function coursepress_custom_enroll_for_all( $student_id ) {
        /**
         * get post id for anny published courses
         */
        $args = array(
            'post_type' => CoursePress_Data_Course::get_post_type_name(),
            'nopaging' => true,
            'status' => array( 'publish' ),
            'fields' => 'ids',
        );
        $the_query = new WP_Query( $args );
        if ( $the_query->have_posts() ) {
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                $course_id = get_the_ID();
                /**
                 * avoid to add to full courses
                 */
                if ( CoursePress_Data_Course::is_full( $course_id ) ) {
                    continue;
                }
                /**
                 * enroll student to course
                 */
                CoursePress_Data_Course::enroll_student( $student_id, $course_id );
            }
        }
    }

    Let me know if this one will start to work correctly on your site.

    kind regards,
    Kasia

  • Tom
    • Site Builder, Child of Zeus

    Ok so after trying to sort through everything I think the problem is actually bigger or not related at all.

    Originally I used Membership 2 and Coursepress Pro. After choosing the membership option the code above would auto enrol users to ALL courses. However, I switched from Membership 2 to WooCommerce due to currency issues.

    I didn't remove the code above however I did have to add another duplicated course to handle subscriptions, therefor the function that enrolled all users on all courses wasnt relevant.

    That being said, WooCommerce automatically worked with Coursepress by auto enrolling students on the course / product they had purchased. However this is the part which is no longer working?

    The original code did break woocommerce although it was never actually required so has been removed however there seems to be a change where woocommerce no longer auto enrolls students onto the course the purchase?

  • Rupok
    • Support Ninja

    Hi Tom,

    That being said, WooCommerce automatically worked with Coursepress by auto enrolling students on the course / product they had purchased... ... ... The original code did break woocommerce although it was never actually required so has been removed however there seems to be a change where woocommerce no longer auto enrolls students onto the course the purchase?

    Can you please confirm if WooCommerce automatically worked with CoursePress by auto enrolling students on the course after the CoursePress 2.0 update?

    I guess, this is a different issue than the 500 error. So I'll suggest you to open a new thread regarding this. Having different threads for different issues helps both you and us to track down steps taken already and also facilitates the troubleshooting process as new thread gets specific attention defined in the thread description.

    I hope you understand. Our support staffs will jump in within minutes after you create a new thread.

    Have a nice day. Cheers!
    Rupok

  • Kasia Swiderska
    • Support nomad

    Hello Tom,

    I'm terribly sorry for all the misunderstangings on our side. You send us login to your site via email and I allowed myself to check your site.
    I believe I found problem with students not enrolled in course.
    You are using WooCommerce Stripe Gateway plugin to handle Stripe payments with option "Capture charge immediately" - so that option should guarentee that when payment is done order will change instantly to "Complete". But this is not happening - you have to go to orded and click "Complete" button on each of the order

    Only marking order as Complete allows users to get access to courses - without that for WooCommerce payment is not done.
    This is not something CoursePress can control - that is on WooCommerce side. I believe this is error in plugin that adds Stripe gateway to WooCommerce and this has to be fixed by WooCommerce developers (that gateway is not our plugin).

    I tested this on your site - I bought Demo course - wasn't enrolled until I clicked "Complete" on orders list. Then I got access to course and I could start learning.
    You can see that wpmudev user is student to that course.

    Please check if this will work also for your test purchases.

    kind regards,
    Kasia

  • Tom
    • Site Builder, Child of Zeus

    Hi Kasia Swiderska,

    Ok thanks for your reply.

    I have contacted woocommerce and hope I hear will back however I feel I will get a response saying that this is a coursepress issue rather than in their plugin.

    Using the old version of coursepress resolves the issue.

    Scenarios:

    Coursepress v1.3.4.3 + Woocommerce Stripe Gateway 3.0.7 + Woocommerce 2.6.14 = WORKING

    Courspress 2.0.4 + Woocommerce Stripe Gateway 3.0.7 + Woocommerce 2.6.14 = NOT WORKING

    Coursepress v1.3.4.3 + Older versions of Stripe & Woocommerce = WORKING

    Do you see that the only thing that is causing the issue is coursepress pro, specifically the 2.0 update :disappointed:

  • Tom
    • Site Builder, Child of Zeus

    Kasia Swiderska - UPDATE on the above.

    I attempted to follow the steps you had taken and have found another problem.

    While clicking the complete order button (as you have pictured above) does turn the student into a user it does't however it doesnt somehow give them access to the modules/units page... it gives them access to the actual module (unit), but not the modules(units) page. eg domain.com/courses/my-course/units

    - Student is given access to the page of modules (units) however no units are actually displayed.
    - Student is listed as being enrolled on 1 course (admin >CP Pro > Students > Number of Courses)
    - When you click on that number you are directed to a page titled 'Student Profile' however it states 'Student not found'
    - When you look at the courses within admin (CP Pro > Courses > Students of specific course) they are listed.

    For this issue which is surely related as it was working well before update I have deactivated all plugins and also tried the coursepress theme.

  • Kasia Swiderska
    • Support nomad

    Hello Tom,

    We did more testing with that stripe gateway - apparently in description there was information missing - autocomplete works if product is virtual AND downloadable. If product is only virtual autocomplete will not work. But changing its type to also downloadable makes autocompletion working.

    I changed demo course product to downloadable and purchased it with Luis account - got access to course and also units for my users are showing and I can follow up with course.

    Please check if those findings are also working for you - on our side we created task for our developers so products created for Woo will be virtual and downloadable to avoid further issues with autocompletion of payments.

    If you will find any more problems can you respond to last Luis email with FTP access? Credentials that you previously send us are not working :slight_frown:

    As for students profiles showing "Student not found." - I did replicate this is on site were there was no Woo, so that is bug in COursePress and I'm reporting this to developers.

    kind regards,
    Kasia

  • Tom
    • Site Builder, Child of Zeus

    Whey, we are finally there!!

    I did try this before and it must have worked however I was not directly checking the admin area to see if the user was enrolled and was instead checking the front end modules page.

    As I mentioned, the actual module itself works fine however the page that displays the list of modules did not. This is what led me to believe that the student was not enrolled.

    I managed to work out that if the user role was admin they could view the modules page however if they were set to customer they were not. This meant it was probably a setting in coursepress.

    Coursepress 2 updated the course setup area in dashboard and gives you the option to show or not show module headers. It's default must be to hide hence why my modules/units page was blank.

    Thanks for you help and I think that I can finally launch the course!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.