Action uncanny-learndash-groups

ulgm_after_license_group_is_inserted

Fires after a license group is successfully inserted into the database, providing access to group ID and arguments.

add_action( 'ulgm_after_license_group_is_inserted', $callback, 10, 3 );

Description

Fires after a license group is successfully inserted. Developers can use this hook to perform custom actions or integrations following the creation of a new license group, such as updating related data or triggering notifications. It passes the group ID, original group arguments, and the current object for context.


Usage

add_action( 'ulgm_after_license_group_is_inserted', 'your_function_name', 10, 3 );

Parameters

$group_id (mixed)
This parameter contains the unique identifier for the license group that has just been inserted.
$ld_group_args (mixed)
The ID of the license group that has just been inserted.
$this (mixed)
This parameter contains the arguments used to create the license group.

Examples

// Hook into the ulgm_after_license_group_is_inserted action to perform additional tasks after a license group is inserted.
// This example demonstrates how to log the inserted group ID and its arguments, and potentially update a custom meta field on the user.
add_action( 'ulgm_after_license_group_is_inserted', 'my_custom_ulgm_callback', 10, 3 );

/**
 * Custom callback function executed after a license group is inserted.
 *
 * @param int   $group_id      The ID of the newly inserted license group.
 * @param array $ld_group_args An array of arguments used to create the license group.
 * @param object $plugin_instance  The instance of the plugin class that triggered the action.
 */
function my_custom_ulgm_callback( $group_id, $ld_group_args, $plugin_instance ) {

	// Log the inserted group ID and its arguments for debugging purposes.
	error_log( "License group inserted with ID: " . $group_id );
	error_log( "License group arguments: " . print_r( $ld_group_args, true ) );

	// Example: If the group represents a specific product, and we want to associate
	// this group with the user who purchased it.
	// We'll assume $ld_group_args contains a 'product_id' key.
	if ( isset( $ld_group_args['product_id'] ) && ! empty( $ld_group_args['product_id'] ) ) {
		$product_id = $ld_group_args['product_id'];

		// Attempt to find the user associated with this purchase.
		// This might require accessing the order details, which isn't directly provided here.
		// For a realistic scenario, you might need to query the order that triggered this.
		// For demonstration, let's assume we can get a user ID from somewhere, perhaps from
		// a transient set earlier or by inferring it if possible.
		// A more robust solution would involve retrieving the order ID and then the customer ID.

		// Placeholder for user ID retrieval. In a real scenario, you'd get this from the order.
		// For instance, if the order object was passed or retrievable.
		$user_id = null; // Replace with actual user ID retrieval logic.

		if ( $user_id ) {
			// Update user meta to record the associated product/license group.
			// This assumes you have a way to map the purchase to a specific user.
			// For example, adding the product ID as a custom field for the user.
			$existing_products = get_user_meta( $user_id, 'purchased_license_groups', true );
			if ( ! is_array( $existing_products ) ) {
				$existing_products = array();
			}
			if ( ! in_array( $product_id, $existing_products ) ) {
				$existing_products[] = $product_id;
				update_user_meta( $user_id, 'purchased_license_groups', $existing_products );
				error_log( "Associated product ID {$product_id} with user ID {$user_id}." );
			}
		}
	}

	// You could also trigger other actions, send notifications, or update plugin settings here.
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/woocommerce/woocommerce-license.php:1101

if ( 'yes' !== get_option( 'do_not_add_group_leader_as_member', 'no' ) ) {
			Group_Management_Helpers::add_existing_user( array( 'user_email' => $user->user_email ), true, $group_id, $order_id, SharedFunctions::$redeem_status, false, false, false, true );
		}

		SharedFunctions::remove_transient_cache( 'all' );

		do_action( 'uo_new_group_purchased', $group_id, $user->ID );
		do_action( 'ulgm_after_license_group_is_inserted', $group_id, $ld_group_args, $this );
	}


	/**
	 * @param $order_id
	 */
	public function woocommerce_redirect_to_group( $order_id ) {


Scroll to Top