Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Dziękuję. Rozwiązało to problem  “Ups… Trafiliśmy na przeszkodę ;(”.

    Co do błędu 503, to się nie wypowiem, bo nie korzystam z szybkiego checkoutu od Furgonetki.

    Dzień dobry,
    Mam dokładnie ten sam problem w wersji 1.6.3, jeśli chodzi o “Ups… Trafiliśmy na przeszkodę ;(”.

    Poprzednio jak miałem podobny problem, okazało się, że blokowane były pliki cookies dla strony w przeglądarce, jednak tym razem odblokowanie nie pomaga.

    @furgonetka czy można prosić o wsparcie?

    Thread Starter stepello

    (@stepello)

    Cześć @iworks,

    W polu:

    WPA -> WooCommerce -> Ustawienia -> Omnibus -> Wiadomości

    Pole: “Brak poprzedniej ceny

    Mam ustawione “Wyświetl bieżącą cenę regularną”

    @jobayertuser

    I am using the 2.6.0 version, and it still did not work correctly for me.
    Are there any additional actions required when updating to 2.6.0 from previous version for it to work correctly?

    Since Tutor team is not very supportive with this matter, I decided to toggle this issue on my own and actually succeeded 😀

    The issue took place in the first place because when customer who never made order in our shop (therefore no account) started to fill in checkout fields Woocommerce created a draft order. Then tutor based on that order would create post (post type: tutor_enrolled) in wp-posts table. But since at this stage there is no customer_id it would set post_author to 0. And you need to know that the enrollment in Tutor is dependent on this post (it needs to have type: tutor_enrolled, contain customer_id as post_author and have status completed, and reference correct course).

    Since in my case customer account is created when customer presses “Order” on checkout, we have the customer_id at the point when order changes status. From there the fix is to modify 2 tutor php files:

    1. public_html/kursy/wp-content/plugins/tutor/classes/WooCommerce.php
    2. public_html/kursy/wp-content/plugins/tutor/classes/Utils.php

    Please note the location of those files might be different in your case, but it should not be an issue for you to find it 😉

    In Woocommerce.php we modify function: enrolled_courses_status_change to this (change in bold):

    /**
         * Take enrolled course action based on order status change
         *
         * Order auto complete
         *
         * @param int    $order_id  wc order id.
         * @param string $status_from  from status.
         * @param string $status_to  to status.
         *
         * @return void
         */
        public function enrolled_courses_status_change( $order_id, $status_from, $status_to ) {
            if ( ! tutor_utils()->is_tutor_order( $order_id ) ) {
                return;
            }
    
            $enrolled_ids_with_course = tutor_utils()->get_course_enrolled_ids_by_order_id( $order_id );
    
            if ( $enrolled_ids_with_course ) {
                $enrolled_ids = wp_list_pluck( $enrolled_ids_with_course, 'enrolled_id' );
    
                if ( is_array( $enrolled_ids ) && count( $enrolled_ids ) ) {
                    foreach ( $enrolled_ids as $enrolled_id ) {
                        /**
                         * If order status is processing and payment is not cash on
                         * delivery then mark enrollment as completed.
                         *
                         * Note: Order status processing simply mean customer have done
                         * payment.
                         *
                         * @since v2.0.5
                         */
                        if ( self::should_order_auto_complete( $order_id ) ) {
                            // Mark enrollment as completed.
                            tutor_utils()->course_enrol_status_change( $enrolled_id, 'completed', $order_id  );
                            // Mark WC order as completed.
                            self::mark_order_complete( $order_id );
                        } else {
                            tutor_utils()->course_enrol_status_change( $enrolled_id, $status_to, $order_id  );
                        }
    
                        // Invoke enrolled hook.
                        if ( 'completed' === $status_to ) {
                            $user_id   = get_post_field( 'post_author', $enrolled_id );
                            $course_id = get_post_field( 'post_parent', $enrolled_id );
                            do_action( 'tutor_after_enrolled', $course_id, $user_id, $enrolled_id );
                        }
                    }
                }
            }
        }

    Then in the Utils.php the change is much heavier so just compare it with what you already have. Function that needs modification is: course_enrol_status_change

        /**
         * Enrol Status change
         *
         * @since 1.6.1
         *
         * @param bool   $enrol_id enrol id.
         * @param string $new_status new status.
         * @param int $order_id order id
         *
         * @return mixed
         */
        public function course_enrol_status_change( $enrol_id = false, $new_status = '', $order_id = 0 ) {
            if ( ! $enrol_id ) {
                return;
            }
    
            global $wpdb;
    
            // Get customer ID from the order
            $order = wc_get_order( $order_id );
    
            if ( $order && is_a( $order, 'WC_Order' ) ) {
                $customer_id = $order->get_customer_id();
        
                if ( $customer_id ) {
                    // Trigger action before the status change
                    do_action( 'tutor/course/enrol_status_change/before', $enrol_id, $new_status);
        
                    // Update post status, post author, and post modified time
                    $result = $wpdb->update(
                        $wpdb->posts,
                        array(
                            'post_status'   => $new_status,
                            'post_author'   => $customer_id,
                        ),
                        array( 'ID' => $enrol_id )
                    );
        
                    // Trigger action after the status change
                    do_action( 'tutor/course/enrol_status_change/after', $enrol_id, $new_status);
        
                    // Check and log the result
                    if ( $result === false ) {
                        error_log( "Failed to update post_author for enrol_id: $enrol_id" );
                    }
                }
            }
        }

    And that would be all. Remember that this will be overridden when you update Tutor!!!

    I tested it with Paypal payment (order closed automatically) and bank transfer (manually close order) in both cases it worked correctly.

    If someone has an idea how to implement this in functions.php of child theme, please let me know!

    I had some messages exchanged with Tutor team regarding this issue, and they were stating that enrollment issue is due to 100% coupon (I used that for testing) or price set to 0. This is not true! It’s because this entry to wp-posts table when woocommerce saves draft order. I’m not that used to github repos and don’t know how suggest it there, so please Tutor team fix it for next release, and I don’t mind you using this code 😉

    @valuepage
    I think your issue is a bit different. In our case, the issue is that the Order is visible in Tutor, but the student is not enrolled correctly.

    However, I also had similar problem as you (Woocommerce was showing order and Tutor not). For me the issue was fixed when I changed i WooCommerce Settings >> Advanced >> Featured following settings:

    • WordPress posts storage (legacy) as checked
    • High-performance order storage as unchecked
    • Enable compatibity mode as checked
    • Enable WooCommerce analitics as checked

    Here grab a screenshot: https://prnt.sc/pMh921nc5M7g

    I have exactly the same problem.
    In my case the issue is 100% cases when user is registered during checkout. I the user buys the course when he already has an account and is logged in, it will enroll more often than not.

Viewing 8 replies - 1 through 8 (of 8 total)