Home / Admin / Change a license activation limit prgramatically.
Duplicate Snippet

Embed Snippet on Your Site

Change a license activation limit prgramatically.

This snippet is an example of changing the activation limit on a license key based on conditional logic. This is useful if you need to change the activation limit for a product but still allow past customers to have their original activation limit.

Code Preview
php
<?php
/**
 * Conditionally alter the activation limit for the a license key.
 * 
 * Example: Licenses created prior to 2020 are set to unlimited.
 * 
 * @param int $limit         The current activation limit.
 * @param int $download_id   The download ID for the license.
 * @param int $license_id    The ID of the license.
 * @param int|null $price_id The variation price ID for the license (numeric for variable priced products, null it not)
 * 
 * @return int
 */
function eddwp_change_license_limit( $limit, $download_id, $license_id, $price_id ) {
	// Change the limit if a license was purchase prior to 2020 using the date_created property.
	$license = edd_software_licensing()->licenses_db->get( $license_id );
	if ( empty( $license ) ) {
		return $limit;
	}
	if ( ! empty( $license->date_created ) && strtotime( $license->date_created ) < strtotime( '2020-01-01' ) ) {
		$limit = 0;
	}
	return $limit;
}
add_filter( 'edd_get_license_limit', 'eddwp_change_license_limit', 10, 4 );

Comments

Add a Comment