Support

Home Forums Event Espresso Premium how can i enable/disable payment methods for different event in EE4

how can i enable/disable payment methods for different event in EE4

Posted: July 18, 2014 at 11:22 am


Sudhir

July 18, 2014 at 11:22 am

hi team
In EE4
is it possible to enable or disable a payment method for one particular event ?

basically i want to enable check only for selective events
keeping paypal enabled for others events

pls help to reply soon ..thanks


Michael Nelson

  • Support Staff

July 18, 2014 at 3:19 pm

currently you can’t do that in EE4. That feature has been requested previously and we do have plans to implement it, although there is no current estimated delivery date.

It might be possible if you’re willing to tweak some of the single page checkout code. Basically you would just see what event the user has registered for, and then hide the check gateway if it’s no in the list of allowed events. Would you like some tips on how to do that?


Sudhir

July 18, 2014 at 8:39 pm

Dear Micheal
yes this should solve my purpose

pls suggest what i need to do

thanks


Sudhir

July 21, 2014 at 8:53 pm

im waiting for your response


Dean

July 22, 2014 at 1:32 am

Hi,

I’ve sent Mike a message regarding this, he will be in touch as soon as possible.


Sudhir

July 22, 2014 at 2:34 am

ok thanks Dean


Dean

July 22, 2014 at 3:16 am

No problem, sorry for the delay.


Michael Nelson

  • Support Staff

July 23, 2014 at 11:24 am

sorry I was hoping the developer who deals more with single page checkout would be able to comment in, but he’s pretty swamped.

in ee4, early on in the page loading process all the gateways are constructed and add a callback on the ‘AHEE__display_payment_gateways’ action, so that when that action is fired (ie ‘do_action’) in the modules/single_page_checkout/templates/registration_page_payment_options.template.php, each active gateway’s espresso_display_payment_gateways() method is called, which echoes out the HTML to add the gateway as an option.
So you can either try to temporarily make a gateway ‘inactive’ based on the events in the cart BEFORE any of the gateways are constructed and hook into ‘AHEE__display_payment_gateways’, OR you can try to remove the gateways callbacks on that action before it is called. I’m inclined to try the latter.

So on an earlier than ‘AHEE__display_payment_gateways’, like ‘AHEE__registration_page_payment_options__payment_info_table_amount_owing_row_end’ (which is also in the same template file, just a few lines earlier), you could run some code like the following:


add_action('AHEE__registration_page_payment_options__payment_info_table_amount_owing_row_end', 'espresso_hide_gateways_for_certain_events');
function espresso_hide_gateways_for_certain_events(){
	$events_which_dont_use_invoice = array( 9, 23 );
	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 $datetime ){
				if( in_array( $datetime->get('EVT_ID'), $events_which_dont_use_invoice ) ){
					espresso_dont_show_certain_gateways();
				}
			}
		}
	}
}

function espresso_dont_show_certain_gateways(){
	$gateway_class_names_to_not_show = array('EE_Check');
	foreach( EEM_Gateways::instance()->get_gateway_instances() as $gateway){
		if( in_array( get_class($gateway), $gateway_class_names_to_not_show) ){
			remove_action('AHEE__display_payment_gateways', array( $gateway, 'espresso_display_payment_gateways'));
		}
	}
}

This code could be inserted into your theme’s functions.php file.

If users have registered for an event with ID 9 or 23, it will hide the Check gateway. So if you wanted it to include different events you’d have to manually change that array of IDs, or if you wanted to hide different gateways you’d have to change the array used in espresso_dont_show_certain_gateways() too.

You might want to add more logic about how those arrays are chosen. For example, you could get the list of events using a database query, searching for events with a particular postmeta value (it would probably be easiest to use get_posts() for this)

The support post ‘how can i enable/disable payment methods for different event in EE4’ 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