Created
September 21, 2015 19:31
-
-
Save DevinWalker/2c8f9b2a410043ab947a to your computer and use it in GitHub Desktop.
Determine if a user is a recent donor (last 30 days) with this conditional check.
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 | |
/** | |
* Is User Recent Donor (Rename/Prefix) | |
* | |
* @description: Display Donors from Last 30 Days | |
* | |
* @return bool | |
*/ | |
function my_give_is_user_recent_donor() { | |
$recent_donor = false; | |
//Only if user is logged in & if this user is a donor | |
if ( is_user_logged_in() && give_has_purchases() ) { | |
//Cool, they've donated... get their donation history | |
$user_donations = give_get_users_purchases(); | |
//Sanity check | |
if ( empty( $user_donations ) ) { | |
return false; | |
} | |
//Loop through donations | |
foreach ( $user_donations as $donation ) { | |
//Now check if there's a donation within the last 30 days... | |
if ( strtotime( $donation->post_date ) > strtotime( '-30 days' ) ) { | |
//Sweet, they have... flag it! | |
$recent_donor = true; | |
} | |
} | |
} | |
return $recent_donor; | |
} | |
//User the conditional function | |
if ( my_give_is_user_recent_donor() ) { | |
//Do something... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment