Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Last active September 22, 2020 17:20
Show Gist options
  • Save dparker1005/d013c5743e5773a423df320c2ed5ea59 to your computer and use it in GitHub Desktop.
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.
<?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