Today we investigate the WooCommerce Checkout and explicitly at how to cripple an installment portal (for example PayPal) if certain item classifications are in the truck.
add_filter( ‘woocommerce_available_payment_gateways’, ‘ikodes_unset_gateway_by_category’ );
function ikodes_unset_gateway_by_category( $available_gateways ) {
global $woocommerce;
$unset = false;
$category_ids = array( 123, 111 );
foreach ( $woocommerce->cart->cart_contents as $key => $values ) {
$terms = get_the_terms( $values[‘product_id’], ‘product_cat’ );
foreach ( $terms as $term ) {
if ( in_array( $term->term_id, $category_ids ) ) {
$unset = true;
break;
}
}
}
if ( $unset == true ) unset( $available_gateways[‘cheque’] );
return $available_gateways;
}