Disable Payment Method for Specific Category

add_filter( 'woocommerce_available_payment_gateways', 'unset_gateway_by_category' ); function unset_gateway_by_category( $available_gateways ) { if ( is_admin() ) return $available_gateways; if ( ! is_checkout() ) return $available_gateways; $unset = false; $category_ids = array( 8, 37 ); //change category id here foreach ( WC()->cart->get_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; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.