Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created May 17, 2018 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/c87f5bf42f18380fa6b218dbc5734a34 to your computer and use it in GitHub Desktop.
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
<?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