Last active
September 22, 2020 17:20
-
-
Save dparker1005/d013c5743e5773a423df320c2ed5ea59 to your computer and use it in GitHub Desktop.
Add account creation fee for new users or users who have not renewed their membership within 1 month.
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 | |
// Copy from below here... | |
/** | |
* Add account creation fee for new users or users who have not | |
* renewed their membership within 1 month. | |
*/ | |
function my_pmpro_add_account_creation_fee( $checkout_level ) { | |
// If user currently has a membership level, don't apply fee | |
if ( ! empty( pmpro_getMembershipLevelsForUser() ) ) { | |
return $checkout_level; | |
} | |
// Get user's most recent enddate | |
global $wpdb; | |
$user_id = get_current_user_id(); | |
$enddate_query_result = $wpdb->get_row( | |
"SELECT enddate | |
FROM {$wpdb->pmpro_memberships_users} | |
WHERE user_id = $user_id | |
AND status <> 'active' | |
ORDER BY id DESC | |
LIMIT 1" | |
); | |
// If this is a new user or enddate is over a month old, add fee | |
if ( empty ( $enddate_query_result ) || ! isset( $enddate_query_result->enddate ) || time() > strtotime( '+ 1 month', strtotime( $enddate_query_result->enddate ) ) ) { | |
$checkout_level->initial_payment += 15; | |
} | |
return $checkout_level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmpro_add_account_creation_fee' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment