Created
July 1, 2014 14:48
-
-
Save strangerstudios/46bd2828648552a3efce to your computer and use it in GitHub Desktop.
Code to get PMPro Gift Levels and PMPro Set Expiration Dates to play together nicely.
This file contains 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
/* | |
Define Gift Levels | |
*/ | |
function init_gift_level() | |
{ | |
//define the levels | |
global $pmprogl_gift_levels; | |
$pmprogl_gift_levels = array( | |
4 => array( // "Purchase Gift" level ID | |
'level_id' => 1, // Membership Level ID of the gift membership level. | |
'initial_payment' => 0, // The initial payment for the gift membership level. | |
'billing_amount' => 0, // The recurring billing amount for the gift membership level. | |
'cycle_number' => 0, // The number of billing cycles for the gift membership level. | |
'cycle_period' => '', // The billing cycle period. Possible values are "Day", "Week", "Month", and "Year" (without the quotes). | |
'billing_limit' => 0, // The billing cycle limit for the gift membership level. | |
'trial_amount' => 0, // The trial amount for the gift membership level. | |
'trial_limit' => 0, // The number of cycles the trial should last for the gift membership level. | |
'expiration_number' => 1, // The number of "experiation_period"s before the gift membership level expires. | |
'expiration_period' => 'Year' // The duration of the period used by "expiration_number". Possible values are "Day", "Week", "Month", and "Year" (without the quotes). | |
) | |
); | |
} | |
add_action('init', 'init_gift_level'); | |
/* | |
If a gift level is purchased, copy the set expiration date if applicable. | |
*/ | |
function pmpro_after_checkout_gift_level_set_expiration($user_id) | |
{ | |
global $wpdb, $pmpro_level, $pmprogl_gift_levels; | |
//only if the set expiration dates plugin is active | |
if(!function_exists('pmpro_saveSetExpirationDate')) | |
return; | |
//check if we're checking out for a gift level | |
if(!empty($pmprogl_gift_levels) && !empty($pmpro_level) && !empty($pmprogl_gift_levels[$pmpro_level->id])) | |
{ | |
//get last gift code | |
$gift_codes = get_user_meta($user_id, 'pmprogl_gift_codes_purchased', true); | |
//not sure why we wouldn't find any, but just in case | |
if(empty($gift_codes)) | |
return; | |
//get the last one | |
$last_gift_code = end($gift_codes); | |
//again, just in case | |
if(empty($last_gift_code)) | |
return; | |
//look for a set expiration date | |
$set_expiration_date = pmpro_getSetExpirationDate($pmprogl_gift_levels[$pmpro_level->id]['level_id']); | |
//save it | |
if(!empty($set_expiration_date)) | |
{ | |
pmpro_saveSetExpirationDate($pmprogl_gift_levels[$pmpro_level->id]['level_id'], $set_expiration_date, $last_gift_code); | |
} | |
} | |
} | |
add_action('pmpro_after_checkout', 'pmpro_after_checkout_gift_level_set_expiration', 20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment