Created
June 25, 2014 11:50
-
-
Save viruthagiri/e09e299fced1bdcb123c 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 | |
| //license limit | |
| function pw_edd_sl_license_at_limit( $ret = false, $license_id = 0, $limit = 0, $download_id = 0 ) { | |
| $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 ) { | |
| switch( $price_id ) { | |
| case 0: | |
| $limit = 1; | |
| break; | |
| case 1: | |
| $limit = 2; | |
| break; | |
| case 2: | |
| $limit = 3; | |
| break; | |
| case 3: | |
| $limit = 4; | |
| break; | |
| case 4: | |
| $limit = 5; | |
| break; | |
| case 5: | |
| $limit = 6; | |
| break; | |
| case 6: | |
| $limit = 7; | |
| break; | |
| case 7: | |
| $limit = 8; | |
| break; | |
| case 8: | |
| $limit = 9; | |
| break; | |
| case 9: | |
| $limit = 10; | |
| break; | |
| } | |
| $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; | |
| } | |
| } | |
| } | |
| return $ret; | |
| } | |
| add_filter( 'edd_sl_license_at_limit', 'pw_edd_sl_license_at_limit', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment