-
-
Save onetarek/8758817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Easy Digital Downloads - Variable Pricing License Activation Limits | |
Plugin URL: http://easydigitaldownloads.com/extension/ | |
Description: Limit the number of license activations permitted based on variable prices. This plugin has not been published officially yet. The plugin author gave this codes in a support ticket. So don't rellay on it completely. | |
Version: 1.1 | |
Author: Pippin Williamson | |
Author URI: http://pippinsplugins.com | |
Contributors: mordauk , oneTarek | |
*/ | |
#Tested and working fine for me. | |
#Bug fix: Able to check when site limit set to 0 means unlimited. | |
function pw_edd_sl_license_at_limit( $ret = false, $license_id = 0, $limit = 0, $download_id = 0 ) { | |
$variable_pricing = edd_has_variable_prices( $download_id ); | |
if(!$variable_pricing){return $ret;} #we want this filter only for varibale pricing option. | |
$prices = edd_get_variable_prices( $download_id ); | |
$limit_list=array(); | |
foreach($prices as $price) | |
{ | |
if(isset($price['limit'])){$lim=absint($price['limit']);}else{$lim=0;} | |
$limit_list[]=$lim; | |
} | |
$purchase_id = get_post_meta( $license_id, '_edd_sl_payment_id', true ); | |
$purchase_date = new DateTime( get_post_field( 'post_date', $purchase_id ) ); | |
$limit_date = new DateTime( '2013-01-01' ); | |
if( $purchase_date < $limit_date ) { | |
// licenses purchased before January 1, 2013 are unlimited | |
return false; | |
} | |
$purchase_details = edd_get_payment_meta_cart_details( $purchase_id ); | |
$price_id = false; | |
foreach( $purchase_details as $item ) { | |
if( $item['id'] == $download_id ) { | |
if( ! empty( $item['item_number']['options'] ) ) { | |
foreach( $item['item_number']['options'] as $option ) { | |
$price_id = (int) $option['price_id']; | |
} | |
} | |
} | |
} | |
if( $price_id !== false ) { | |
if(isset($limit_list[$price_id])) | |
{ | |
$limit =$limit_list[$price_id]; | |
}#else no change of $limit | |
$site_count = absint( get_post_meta( $license_id, '_edd_sl_site_count', true ) ); | |
// check to make sure a limit is in place | |
if( $limit > 0 ) { | |
if( $site_count >= absint( $limit ) ) { | |
$ret = true; // license is at limit | |
} | |
else | |
{ | |
$ret=false; // license is not at limit . Added by oneTarek | |
} | |
} | |
else | |
{ | |
$ret=false; // license is not at limit. When limit=0 Licesne is for unlimited usages. Added by oneTarek | |
} | |
} | |
return $ret; | |
} | |
add_filter( 'edd_sl_license_at_limit', 'pw_edd_sl_license_at_limit', 10, 4 ); | |
#================================================================================= | |
function otk_edd_download_price_table_head($post_id=0) | |
{ | |
echo '<th>Site Limit <span title="Set the limitation of how many website a single liecnse can be used in. Put 0 for unlimited website" style="color:#0074A2; cursor:pointer">(?)</a></th>'; | |
} | |
add_action('edd_download_price_table_head', 'otk_edd_download_price_table_head', 10, 1); | |
function otk_edd_price_row_args($args, $value) | |
{ | |
//echo "<pre>"; print_r($args); echo "</pre>"; | |
if(isset($value['limit'])){$limit=absint($value['limit']);}else{$limit=1;} | |
$args['limit']=$limit; | |
return $args; | |
} | |
add_filter('edd_price_row_args', 'otk_edd_price_row_args', 10, 2); | |
function otk_edd_download_price_table_row($post_id, $key, $args) | |
{ | |
$limit=absint($args['limit']); | |
?> | |
<td><input type="text" name="edd_variable_prices[<?php echo $key; ?>][limit]" id="edd_variable_prices[<?php echo $key; ?>][limit]" value="<?php echo $limit; ?>" size="3" style="width:100%"/></td> | |
<?php | |
} | |
add_action('edd_download_price_table_row', 'otk_edd_download_price_table_row', 10, 3 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment