Created
May 17, 2018 10:17
-
-
Save Pebblo/c87f5bf42f18380fa6b218dbc5734a34 to your computer and use it in GitHub Desktop.
Example of how to show only a 'check' payment method if any of the tickets have the string 'check' within the ticket name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Please do add the opening PHP tag if you already have one. | |
function tw_ee_only_check_payment_method_based_on_ticket_name($payment_methods, $transaction, $scope) { | |
//Double check we have a transaction object. | |
if ( $transaction instanceof EE_Transaction) { | |
//Initialize an array used to hold the ticket names. | |
$ticket_names = array(); | |
//Loop over all registrations and add the ticket name for each reg to the ticket_names array. | |
foreach( $transaction->registrations() as $registration ) { | |
$ticket_names[] = $registration->ticket()->name(); | |
} | |
//Loop over ticket_names, if any of them have 'check' in the name then pull a check payment method and return only that. | |
foreach($ticket_names as $ticket_name){ | |
if (strpos($ticket_name, 'check') !== false) { | |
$check_payment_method = EEM_Payment_Method::instance()->get_one_of_type( 'Check' ); | |
if( $check_payment_method instanceof EE_Payment_Method) { | |
$payment_methods = array(); | |
$payment_methods[] = $check_payment_method; | |
break; | |
} | |
} | |
} | |
} | |
return $payment_methods; | |
} | |
add_filter('FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', 'tw_ee_only_check_payment_method_based_on_ticket_name', 20, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment