Change Which Gateways Are Enabled For An Event

Gateway settings (merchant account details etc) must be the same across all events – but it is possible to restrict which gateways appear on which events – for instance to allow PayPal purchases only on some events

To do this we use the eventorganiser_enabled_gateways hook, which filters the enabled gateways.

Step 1: Specify which gateways are available

The easiest way to do this is to use the event custom fields metabox. In this example, we’ll use ‘gateways’ key, and specify the available gateways:

gateway-custom-field

Step 2: Filter the gateways

First we check that we are on a single event page (i.e where the booking form is) before we attempt to filter the list. Next, using the event ID, we retrieve the available gateways that were stored with the key ‘gateways’ in the event’s post meta. If we can’t find that key, we just allow all enabled gateways. Assuming we have found some gateways stored in the event’s post meta, we disable any other gateways.

function filter_my_event_gateways( $enabled_gateways ){

     //$enabled_gateways if an array of the form gateway ID => gateway label    

     //Are we on an event page?
     if( ! is_singular( 'event' ) )
        return $enabled_gateways;

     //Get event ID and the corresponding gateways
     $event_id = get_the_ID();
     $gateways = get_post_meta( $event_id, 'gateways' );

     //If we can't find any gateways stored with this event - use all enabled gateways
     if( false === $gateways )
             return $enabled_gateways;

     //Get only gateways which are both enabled and specified for this event
     $enabled_gateways = array_intersect( $enabled_gateways, $gateways );

     return $enabled_gateways;
}
add_filter( 'eventorganiser_enabled_gateways', 'filter_my_event_gateways' );

Note: if the gateways you have selected for an event have not been enabled on the settings page – there will not appear on the booking form.