<span class="resolved" aria-label="Resolved" title="Topic is resolved."></span>Action triggering twice?

[ad_1]

Replies: 1

I found some suggestions in this forum for using hooks, I am trying to register users to a learndash course based on the form id. This DOES work correctly however… it is being triggered twice each time I register a user with that form and I can’t figure out why.

add_action( 'user_registration_after_register_user_action', 'add_user_to_course_from_form', 10, 3 );
function add_user_to_course_from_form( $valid_form_data, $form_id, $user_id ) {
	if( $form_id == '60'){
		
		$course_ids = [19];
 
		// Add user to each course
		foreach ( $course_ids as $course_id ) {
			ld_update_course_access( $user_id, $course_id, $remove = false );
		}
	}
}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer