Skip to content

Instantly share code, notes, and snippets.

@tobeyadr
Created March 21, 2022 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobeyadr/7bff394e36c3c0797dbf50a4acb74f77 to your computer and use it in GitHub Desktop.
Save tobeyadr/7bff394e36c3c0797dbf50a4acb74f77 to your computer and use it in GitHub Desktop.
Increment the complete lesson count in a custom field
<?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