Guest User

Untitled

a guest
May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php //Please do add the opening PHP tag if you already have one.
  2.  
  3. function tw_ee_only_check_payment_method_based_on_ticket_name($payment_methods, $transaction, $scope) {
  4. //Double check we have a transaction object.
  5. if ( $transaction instanceof EE_Transaction) {
  6.  
  7. //Initialize an array used to hold the ticket names.
  8. $ticket_names = array();
  9.  
  10. //Loop over all registrations and add the ticket name for each reg to the ticket_names array.
  11. foreach( $transaction->registrations() as $registration ) {
  12. $ticket_names[] = $registration->ticket()->name();
  13. }
  14.  
  15. //Loop over ticket_names, if any of them have 'check' in the name then pull a check payment method and return only that.
  16. foreach($ticket_names as $ticket_name){
  17. if (strpos($ticket_name, 'check') !== false) {
  18. $check_payment_method = EEM_Payment_Method::instance()->get_one_of_type( 'Check' );
  19. if( $check_payment_method instanceof EE_Payment_Method) {
  20. $payment_methods = array();
  21. $payment_methods[] = $check_payment_method;
  22. break;
  23. }
  24. }
  25. }
  26. }
  27. return $payment_methods;
  28. }
  29. add_filter('FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', 'tw_ee_only_check_payment_method_based_on_ticket_name', 20, 3 );
Add Comment
Please, Sign In to add comment