Here’s how to disable the payment gateway base on product id(s) or product category . For example if you have 2 products , 1 products will use paypal payment gateway and the other will pay via check.
[membership level=”1″]
function payment_gateway_disable_product_id( $available_gateways ) {
global $woocommerce;
$preneed = false;
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( $product->product_type == 'grouped'){
$checkpost_id=$_product->post->post_parent;
}else{
$checkpost_id=$_product->id;
}
if ( $_product->post->post_parent== $post_id ){
$found = true;
}
if ( $_product->id== 1387 or $_product->id== 1389 or $_product->id== 1391){
$preneed = true;
}
}
// if product not found, add it
} else {
// if no products in cart, add it
//$woocommerce->cart->add_to_cart( $product_id );
}
if ( $preneed==true ) {
unset( $available_gateways['paypal_pro'] );
}else {
unset( $available_gateways['cheque'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_product_id' );
[/membership]

