Forked from strangerstudios/pmpro_after_checkout_gift_level_set_expiration.php
Last active
January 2, 2023 19:33
-
-
Save kimwhite/4f766ab2bd8dcc0e91b3d1036a925bb5 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 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 | |
/* | |
This should allow you to set a calendar end date to work with Gift Memberships. | |
Use at your own risk. | |
If a gift level is purchased, copy the set expiration date if applicable. | |
Must have Gift Membership Add On and with Set Expiration Date being used. | |
*/ | |
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