
Disable Payment Method for Specific Category in WooCommerce
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;
}
Expand Your Digital Horizons With Us
Start a new project or take an existing one to the next level. Get in touch to start
small, scale-up, and go Agile.