Created
March 21, 2022 13:53
-
-
Save tobeyadr/7bff394e36c3c0797dbf50a4acb74f77 to your computer and use it in GitHub Desktop.
Increment the complete lesson count in a custom field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// todo change hook to the one in your LMS | |
add_action( 'lesson_completed', 'increment_lesson_count_custom_field' ); | |
/** | |
* Increment the lesson completed count of the logged in contact | |
* Todo add any relevant arguments to the function | |
* | |
* @return void | |
*/ | |
function increment_lesson_count_custom_field() { | |
// Get the contact record of th current logged-in user | |
$contact = \Groundhogg\get_contactdata(); | |
if ( ! $contact ) { | |
return; | |
} | |
// todo change to your custom field | |
$key = 'lesson_count'; | |
// Increment the count | |
$contact->update_meta( $key, $contact->get_meta( $key ) + 1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment