• Resolved pandamedia

    (@pandamedia)


    Hi,

    I’m currently having an issue with Tutor LMS 2.1.1 and I can’t deal with it, I tried everything I could.

    Current situation:

    I receive payments from an external platform.

    Zapier catches the payment, then I use it to automatically create WooCommerce user, then create WooCommerce order for the product linked to Tutor LMS course.

    WooCommerce product is marked as “single”, “virtual” and “for tutor”.

    Concerns:

    1. When creating the user with Zapier, I cannot see it in the student list.
    2. When creating order with Zapier, it is set as paid and completed, and linked to the good WooCommerce product linked to my course. However, I can’t see the user in the student list nor enrolment list.

    Question:

    How to make Tutor understand that WooCommerce order is OK, and that the user who purchased should be enrolled to my course?

    I guess there is something missing with post_meta regarding the database.

    Any help will be appreciated.

    Cheers.

    EDIT : I previously used FluentCRM which had the “Enroll to course” action, so I basically need to be able to do the same but automatically

    • This topic was modified 1 year, 11 months ago by pandamedia.
    • This topic was modified 1 year, 11 months ago by pandamedia.
    • This topic was modified 1 year, 11 months ago by pandamedia.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Dear @pandamedia

    I am very sorry to inform you that, currently Tutor LMS doesn’t have any support for the Zapier, that’s why you are facing this issue. Maybe in the future, we will introduce support for the Zapier.

    Have a good day.

    Thread Starter pandamedia

    (@pandamedia)

    In case someone needs this, I solved it myself after looking at the documentation.

    /**
     * Autocomplete orders and enroll students
     *
     */
    
    function auto_update_orders_status_from_processing_to_completed(){
    	global $wpdb;
    	// Get all current "processing" customer orders
    	$processing_orders = wc_get_orders( $args = array(
    		'numberposts' => -1,
    		'post_status' => 'wc-processing',
    	) );
    
    	// If there are processing orders
    	if(!empty($processing_orders)) {
    
    		// Browse orders
    		foreach($processing_orders as $order)
    
    			// Update the order to completed
    			$order->update_status( 'completed' );
    
    			// Get order ID and WooCommerce order ID
    		$order_id = $order->ID;
    		$order = wc_get_order( $order_id );
    
    			// Get User ID From Order
    		$user = $order->get_user();
    		$user_id = $order->get_user_id();
    		
    			// Get product from order
    		$items = $order->get_items();
    
    			// Browse products
    		foreach ( $items as $item ) {
    
    			    // Product ID
    			$product_id = $item->get_product_id();
    
    			echo $user_id;
    
    			    // Retrive Related Course ID
    			$sql = "SELECT post_id FROM jungle_postmeta WHERE meta_key = '_tutor_course_product_id' AND meta_value = $product_id";
    			$results = $wpdb->get_results($sql);
    			$course_id = $results[0]->post_id;
    
    			   	// Enroll user
    			$title = __('Course Enrolled', 'tutor')." – ".date_i18n(get_option('date_format')) .' @ '.date_i18n(get_option('time_format') ) ;
    			$enrolment_status = 'completed';
    
    			$enroll_data = apply_filters('tutor_enroll_data',
    				array(
    					'post_type'     => 'tutor_enrolled',
    					'post_title'    => $title,
    					'post_status'   => $enrolment_status,
    					'post_author'   => $user_id,
    					'post_parent'   => $course_id,
    				)
    			);
    
    				// Insert the post into the database
    			$isEnrolled = wp_insert_post( $enroll_data );
    			update_user_meta( $user_id, '_is_tutor_student', time() );
    			update_post_meta( $isEnrolled, '_tutor_enrolled_by_order_id', $order_id );
    			update_post_meta( $isEnrolled, '_tutor_enrolled_by_product_id', $product_id );
    			update_post_meta( $order_id, '_is_tutor_order_for_course', time() );
    			update_post_meta( $order_id, '_tutor_order_for_course_id_'.$course_id, $order_id );
    			
    
    		}
    		
    		
    	}
    }
    add_action( 'init', 'auto_update_orders_status_from_processing_to_completed' );
    add_action( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
    function wc_auto_complete_paid_order( $status, $order_id, $order ) {
    	if ( ! $order->has_status('completed') && $order->get_meta('_order_processed') != 'yes') {
    		$order->update_meta_data('_order_processed', 'yes');
    		$status = 'completed';
    	}
    	return $status;
    }

    Hope it can help someone !

    Cheers and merry xmas ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Zapier + Auto Enrollment’ is closed to new replies.