Ikodes Technology

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;

}





Author Bio

ikodes Technology

Manager of Marketing for Red Stag Fulfillment, an ecommerce fulfillment warehouse that was born out of ecommerce. He has years of experience in ecommerce and business development. In his free time, Jake enjoys reading about business and sharing his own experience with others.

Go Back

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.

    Math Captcha 79 − = 78

    Leave a Reply