Tutor LMS tutorial: Enrol students automatically after checkout?

tutor lms tutorial

Tutor LMS courses can be sold using Woocommerce. After a user purchases a course, ideally he should be enrolled smoothly after making payments i,e after the checkout. Student enrollment is done in two methods- free and paid. Tutor LMS maintains its own orders to determine if a user has purchased a course or not. This video tutorial is for all those course admins who desire to enrol students just after checkout on Woocommerce, that too, automatically.

Video Tutorial

Code for automatically enrolling students

// auto complete from processing

function auto_update_orders_status_from_processing_to_completed(){
// Get all current "processing" customer orders
$processing_orders = wc_get_orders( $args = array(
'numberposts' => -1,
'post_status' => 'wc-processing',
) );
foreach($processing_orders as $order)
$order->update_status( 'completed' );
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;
// end here