Support

Home Forums Event Espresso Premium Disable specific payment method for all but a certain event

Disable specific payment method for all but a certain event

Posted: May 15, 2015 at 8:48 am

Viewing 6 reply threads


Ross Chapman

May 15, 2015 at 8:48 am

Running EE 4.6.23p

Until today, I have only required one active payment method: Credit Card (by way of a custom payment method).

An upcoming event, however, will accept payment by Electronic Funds Transfer in addition to credit card. It is the lone exception to my organization’s standard practice, thus I can’t simply enable EE’s built-in “Bank” (EE_PMT_Bank) payment method since it will appear on all events.

I have written an action handler, appended to my WP theme’s “functions.php” file.


add_action('AHEE__registration_page_payment_options__payment_info_table_tbody_end', 'espresso_show_bank_payment_method_for_certain_events_only');

function espresso_show_bank_payment_method_for_certain_events_only() {
  $event_id = array(65); // Event ID where EFT is required
  foreach(EE_Cart::instance()->get_tickets() as $ticket_line_item) {
    $ticket_obj = $ticket_line_item->ticket();
    if($ticket_obj instanceof EE_Ticket) {
      $datetimes = $ticket_obj->datetimes();
      foreach($datetimes as $dt){
        if(!in_array($dt->get('EVT_ID'), $event_id)) {
          espresso_hide_payment_method('EE_PMT_Bank');
        }
      }
    }
  }
}

function espresso_hide_payment_method($payment_method_type_obj_class) {
  foreach(EEM_Payment_Method::instance()->get_all_active('CART') as $active_payment_method) {
    if(get_class($active_payment_method->type_obj()) == $payment_method_type_obj_class) {
      $active_payment_method->deactivate();
    }
  }
}

Problem is, that nothing happens. No errors are thrown. Likewise, both credit card and bank payment methods remain visible.

I did some rudimentary investigation by adding a filter handler near the payment method selector and dumping the contents each payment object as it was checked and ultimately deactivated: print_r($active_payment_method, true)

I can confirm that the deactivate() method is triggered and associated EE_Payment_Method scope is cleared as expected. Alas, the page markup associated with EE_PMT_Bank is being displayed.

Suggestions?


Lorenzo Orlando Caum

  • Support Staff

May 16, 2015 at 10:05 am

Hi Vincent, this isn’t something that I’m familiar with so I’ve asked a developer for feedback. I’ll update this support post once I have more information.

Thanks


Lorenzo


Ross Chapman

May 19, 2015 at 7:33 am

Fwiw, my code is derived from a suggestion made in the following thread circa July 2014: https://eventespresso.com/topic/how-can-i-enabledisable-payment-methods-for-different-event-in-ee4/

My code isn’t tied to AHEE__display_payment_gateways nor AHEE__registration_page_payment_options__payment_info_table_amount_owing_row_end action handlers cited in the aforementioned thread, however. Grep’ing the EE 4.6.23p codebase (which I have installed) shows no mention of these action handlers though. 🙁


Josh

  • Support Staff

May 19, 2015 at 8:37 am

Hi Vincent,

It turns out the thread from July 2014 applied to Event Espresso 4.4 or earlier. The payment gateways underwent a re-write for 4.6, so that’s why you no longer see those action hooks.

We’re working on adding a new filter (it’s actually been added to a feature branch and is pending review before it can be tested and merged to master). Once it’s been merged to master branch I’ll update this thread and let you know.


Ross Chapman

May 19, 2015 at 9:39 am

Tkx Josh.

In the meantime, is there a particular core file I can hack a workaround into? The payment method <> certain events filter is a “needed it yesterday” sort of thing for my organization.

Near the tail end of “/event-espresso-core-reg/modules/single_page_checkout/templates/payment_options_main.template.php” is an echo $payment_options; statement. If you can point me to the file and function where this snippet is assembled, I can probably figure out a stop-gap measure from there.


Josh

  • Support Staff

May 19, 2015 at 10:56 am

Hi Vincent,

Instead of hacking a workaround in, you can checkout the FET (Feature) branch that has the new filter from our github repository. Here’s a direct link to that branch:

https://github.com/eventespresso/event-espresso-core/tree/FET-8178-filters-for-changing-payment-methods-based-on-events-being-registered-for

Or you can apply the same commit that Mike made, which is right here:

https://github.com/eventespresso/event-espresso-core/commit/777211a7c2761d4f3d26fb134271165a658e3841

The above commit adds a new method and a new filter that can be used to override which payment methods can be selected at checkout.


Josh

  • Support Staff

May 27, 2015 at 12:37 pm

Update: The feature branch was merged in and the new filter is included in the latest release (version 4.6.29.p).

Along with that, there’s a very simple initial commit of a payment methods pro add-on that you can install that will allow for enabling specific methods for specific events via setting a meta key/value in the event editor. Here’s a link to the add-on’s github repository:

https://github.com/eventespresso/eea-payment-methods-pro

Viewing 6 reply threads

The support post ‘Disable specific payment method for all but a certain event’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso