How to auto-activate licenses on purchase

The intention of Digital License Manager is not to auto-activate licenses. We developed bunch of functionality where customers can interact with Licenses, such as manual activations or activations through the API.

However, on some occasions, website owners need to auto-activate licenses.

To auto-activate the assigned licenses when an order is complete, place the snippet in the theme’s functions.php or either in your plugins or mu-plugins.

<?php

add_action( 'dlm_licenses_generated_on_order', function ( $args ) {

	$licenseService = new \IdeoLogix\DigitalLicenseManager\Core\Services\LicensesService();

	if ( empty( $args['licenses'] ) ) {
		return;
	}

	foreach ( $args['licenses'] as $license ) {
		/* @var \IdeoLogix\DigitalLicenseManager\Database\Models\License $license */
		$licenseService->activate( $license->getDecryptedLicenseKey(), [
			'label'  => 'Pre-activated on purchase',
			'source' => \IdeoLogix\DigitalLicenseManager\Enums\ActivationSource::WEB
		] );
	}

} );