1. Go to WP Admin -> Plugins -> Editor -> WPLMS Customizer -> Customizer_class.php
2. Add following lines in the __construct function:
PHP Code:
add_action('bp_after_activation_page',array($this,'activate_free_courses')); // Runs when user activates his account.
3. Add following functions in the class:
PHP Code:
function activate_free_courses(){ if(!is_user_logged_in()) return; $user_id = get_current_user_id(); if ( bp_account_was_activated() ){ // Checks if the Account was activated $args = array( 'post_type' => 'course', 'post_per_page' => -1, 'meta_query'=>array( array( 'key' => 'vibe_course_free', 'value' => 'S', 'compare' => '=', 'type' => 'CHAR' ) ) ); $free_courses = new WP_Query($args); if($free_courses->have_posts()){ while($free_courses->have_posts()){ the_post(); $course_id = get_the_ID(); bp_course_add_user_to_course($user_id,$course_id); } } wp_reset_postdata(); } }
For custom courses:
function activate_free_courses(){ if(!is_user_logged_in()) return; $user_id = get_current_user_id(); $course_ids = array(15,68,78); //Array of course ids you want user to get access to on account creation. foreach($course_ids as $course_id) bp_course_add_user_to_course($user_id,$course_id); }