Gateway filters frontend

Conditionally display gateways

if you wanted to disable a gateway conditionally (lets say no cash on delivery for non logged in users) you could add this to your themes functions.php

wppizza_filter_gateways_orderpage

@param: array
@return: array

example:

add_filter('wppizza_filter_gateways_orderpage', 'my_custom_gateways_filter');
function my_custom_gateways_filter($gateways){
	/* disable Cash on delivery for non-logged in users */
	if( !is_user_logged_in()){
		unset($gateways['COD']);//gateway keys are always uppercase
	}
return $gateways;
}

wppizza_filter_gateways_payment_options

as of wppizza 3.2.5 you can also do something like the following to conditionally enable/disable gateways depending on order value

add_filter('wppizza_filter_gateways_payment_options', 'my_custom_gateways_on_zero', 10 , 3);
function my_custom_gateways_on_zero($gateway_objects, $order_data,  $user_data){

	/*
		just for convenience
	*/
	$cart_total = $order_data['summary']['total'][0]['value'];
	
	/* 
		Example:
		if cart total is zero, disable all credit card payment gateways 
		i.e simply keep COD (which must be enabled for this to work of of course)
	*/
	if(empty($cart_total)){
		foreach($gateway_objects as $id => $obj){	
			
			/* hint: you could - temporarily - do a print_r($id) here to see all the id's associated with any gateways you have enabled */
			
			if($id !== 'COD'){
				unset($gateway_objects->$id);	
			}
		}
	}

	/* 
		Example:	
		if cart total is > zero, disable all NON credit card gateways - if that's what suits you
		you can use both examples in conjunctions with each other of course
	*/	
	if(!empty($cart_total)){
		unset( $gateway_objects->COD );
	}

	/* 
		Example:	
		if cart total is < 25, disable "Credit Card on Delivery" gateway
	*/
	if($cart_total < 25){
		unset($gateway_objects->CCOD);
	}

	/* 
		Note: If you want to conditionally do any of the above depending on if delivery or pickup was selected	
		simply add / wrap into another conditional like so
	*/
	if(!empty($order_data['checkout_parameters']['is_pickup'])){
		/* is pickup */ 
	}else{
		/* is delivery */
	}


return $gateway_objects;
}

For some globally available wppizza functions you could use in your conditionals above, refer to “Global WPPizza Functions”

Allow discounts for credit card payment gateways

By default you can only add dsicounts to COD type gateways as adding a discount to credit card gateways could result in the shop being charged more by the gateway provider than what it would earn with a sale. However, if you need to do this for whatever reason you could use the filter below (using Mollie here as an example gateway)

wppizza_filter_gateway_objects

@param: obj
@return: obj

example:

add_filter('wppizza_filter_gateway_objects', 'myprefix_filter_gateway_objects');
function myprefix_filter_gateway_objects($obj){
	/* 5 EUR/USD/whatever discount */
	$obj->MOLLIE->discounts['fixed'] = 5;
	/* and/or for 5 percent instead */
	$obj->MOLLIE->discounts['percent'] = 5;
return $obj;
}