Guest User

Untitled

a guest
Dec 15th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /*
  2. Add On: PMPro Sponsored Members
  3. Desc: Update the associated discount code's expiration date to match the expiration date of the parent level.
  4. */
  5.  
  6. function pmprosm_pmpro_after_checkout_update_code_expiration($user_id, $order)
  7. {
  8. global $pmpro_level, $wpdb;
  9.  
  10. //get level
  11. if(!empty($pmpro_level))
  12. $level_id = $pmpro_level->id;
  13. elseif(!empty($_REQUEST['level']))
  14. $level_id = intval($_REQUEST['level']);
  15. else
  16. $level_id = false;
  17.  
  18. if(empty($level_id))
  19. return;
  20.  
  21. if (pmprosm_isMainLevel($level_id))
  22. {
  23. $code_id = pmprosm_getCodeByUserID($user_id);
  24.  
  25. $level = pmpro_getMembershipLevelForUser($user_id);
  26.  
  27. if(!empty($level->enddate))
  28. {
  29. $wpdb->update(
  30. $wpdb->pmpro_discount_codes,
  31. array(
  32. 'id'=>max($code_id, 0),
  33. 'expires' => date("Y-m-d", $level->enddate),
  34. ),
  35. array('id' => $code_id)
  36. );
  37. }
  38. }
  39.  
  40. }
  41. add_action("pmpro_after_checkout", "pmprosm_pmpro_after_checkout_update_code_expiration", 15, 2);
Add Comment
Please, Sign In to add comment