5.10.Gateway filter 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”
documentor id 5