Home / Admin / Variable Pricing License Expiration
Duplicate Snippet

Embed Snippet on Your Site

Variable Pricing License Expiration

Set the expiration time for licenses per price option

Code Preview
php
<?php
/**
  * Below are two different filters: one to modify the unit (months, years, or days), and another
  * to modify the length. They are used together to build a full billing cycle for that price ID.
  * So if you enter "months" for price ID 1 in the first filter, and "6" for price ID 1 in the second
  * filter, you get a duration of "6 months".
  */
add_filter( 'edd_sl_download_expiration_unit', function( $unit, $download_id, $price_id ) {
    $your_download_id = 123; // Change this to your download ID.
    if ( (int) $your_download_id !== (int) $download_id ) {
        return $unit;
    }
	if ( ! is_numeric( $price_id ) ) {
		return $unit;
	}
	switch( $price_id ) {
		case 1 :
			$unit = 'months';
			break;
		case 2 :
			$unit = 'years';
			break;
	}
	return $unit;
}, 10, 3 );
add_filter( 'edd_sl_download_expiration_length', function( $length, $download_id, $price_id ) {
    $your_download_id = 123; // Change this to your download ID.
    if ( (int) $your_download_id !== (int) $download_id ) {
        return $length;
    }
	if ( ! is_numeric( $price_id ) ) {
		return $length;
	}
	switch( $price_id ) {
		case 1 :
			$length = 6;
			break;
		case 2 :
			$length = 1;
			break;
	}
	return $length;
}, 10, 3 );

Comments

Add a Comment