Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /**
  2. * Only charge billing amount for renewals.
  3. */
  4. function my_pmpro_checkout_level($level) {
  5. // Only continue for recurring levels.
  6. if( ! pmpro_isLevelRecurring( $level ) ) {
  7. return $level;
  8. }
  9. global $wpdb, $current_user;
  10.  
  11. // Does this user have a membership record for this level within the past 3 months?
  12. $enddate = date('Y-m-d H:i:s', strtotime('-3 months', current_time('timestamp')));
  13. $sql = "SELECT COUNT(id) FROM {$wpdb->pmpro_memberships_users} WHERE user_id = {$current_user->ID} AND membership_id = {$level->id} AND enddate > '{$enddate}' LIMIT 1";
  14. $old_level = $wpdb->get_var($sql);
  15. if($old_level) {
  16. $level->initial_payment = $level->billing_amount;
  17. }
  18. $level->cycle_number = 0;
  19. $level->billing_amount = 0;
  20. $level->cycle_period = '';
  21. return $level;
  22. }
  23. add_action('pmpro_checkout_level', 'my_pmpro_checkout_level');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement