Skip to content

Instantly share code, notes, and snippets.

@AladinDridi
Created February 12, 2018 17:08
Show Gist options
  • Save AladinDridi/c9483c4a244eeeff2bae2bec3a25fbd1 to your computer and use it in GitHub Desktop.
Save AladinDridi/c9483c4a244eeeff2bae2bec3a25fbd1 to your computer and use it in GitHub Desktop.
add_filter('woocommerce_available_payment_gateways','filter_gateways',1);
function filter_gateways($gateways){
global $woocommerce;
$inarray = false;
$specialItem=array(492496,492551,492563,492583,492589,492606,492623,492636,492690,492702,492708,492832,492840,492887,492903,492914,492926,492939,493010,493019,493027,493293,493460,493467);//array contains ids of many products //
foreach ($woocommerce->cart->cart_contents as $key => $values ) {//enumerate over all cart contents
if(in_array($values['product_id'],$specialItem)){//if special item is in it
$inarray = true;//set inarray to true
}
}
if($inarray) {//product is in the cart
unset($gateways['bacs'],$gateways['gpgcheckout']);
} else { unset($gateways['other_payment']);}
return $gateways;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment