Guest User

Untitled

a guest
Feb 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /*
  2. Code demo/proof of concept
  3.  
  4. Premise:
  5. PMPro Sponsored Members dynamic charging. ONLY charge the parent account when a child account actually signs up using the sponsor code.
  6. Basically we're charging the parent account CC when a child account signs up with the code.
  7.  
  8. Limitations...
  9. * Parent account MUST have made an initial purchase
  10. * Currently ONLY works with Stripe
  11. * Code and behavior should be considered HIGHLY EXPERIMENTAL and should be TESTED before use.
  12. * Could cause other issues with reports (untested)
  13. * Parent account does not receive emails when child account checks out (and their CC is charged)
  14.  
  15. */
  16.  
  17. function my_pmpro_after_checkout($user_id, $morder)
  18. {
  19. $parent = pmprosm_getSponsor($user_id);
  20. if(!empty($parent))
  21. {
  22. $parent_order = new MemberOrder();
  23. $parent_order->getLastMemberOrder($parent->ID);
  24.  
  25. $child_order = new MemberOrder();
  26. $child_order->InitialPayment = 10;
  27. $child_order->gateway = "stripe";
  28. $child_order->user_id = $parent->ID;
  29. $child_order->membership_id = 8;
  30. $child_order->notes = "This is a child order for ". $user_id;
  31.  
  32. $parent_order->Gateway->charge($child_order);
  33. }
  34. }
  35.  
  36. add_action('pmpro_after_checkout', 'my_pmpro_after_checkout', 10, 2);
  37.  
  38. function pmpro_sponsored_member_settings {
  39. $pmprosm_sponsored_account_levels = array(
  40. 7 => array(
  41. 'main_level_id' => 7,
  42. 'sponsored_level_id' => array(8),
  43. 'seats' => 0, //0 means unlimited
  44. ),
  45. );
  46. }
  47. }
  48. add_action('init', 'pmpro_sponsored_member_settings');
Add Comment
Please, Sign In to add comment