wcpgsk_restrict_payment_gateways

The Woocommerce Poor Guys Swiss Knife wcpgsk restrict payment gateways function.

Description

wcpgsk_restrict_payment_gateways( $restrict_gateways ); 

Parameters (1)

0. $restrict_gateways
The restrict gateways.

Usage

  1. if ( !function_exists( 'wcpgsk_restrict_payment_gateways' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-poor-guys-swiss-knife/wcpgsk-af.php'; 
  3.  
  4. // The restrict gateways. 
  5. $restrict_gateways = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wcpgsk_restrict_payment_gateways($restrict_gateways); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wcpgsk-af.php  
  1. function wcpgsk_restrict_payment_gateways( $restrict_gateways ) { 
  2. global $woocommerce; 
  3. $arrayKeys = array_keys($restrict_gateways); 
  4. $items = isset($woocommerce->cart->cart_contents) ? $woocommerce->cart->cart_contents : array(); 
  5. $itemGateways = ''; 
  6. if($items) 
  7. foreach($items as $item) 
  8. $itemGateways[] = get_metadata('post', $item['product_id'], 'payment_gateways', false) ; 
  9. if($itemGateways) 
  10. foreach($itemGateways as $gateway) 
  11. if(count($gateway)) : 
  12. foreach($arrayKeys as $key) : 
  13. if(!in_array($key, $gateway)) : 
  14. unset($restrict_gateways[$key]); 
  15. endif; 
  16. endforeach; 
  17. endif; 
  18. return $restrict_gateways;