Blog

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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 89 = 93

Popular Articles

Most Recent Posts

  • All Post
  • Blog
  • Business Supermarket
  • Creative
  • Design
  • Development
  • Digital
  • General
  • Marketing
  • Mobile Development
  • Online Marketing
  • SEO
  • Software Development Company
  • web design
  • Web Development
  • Website
  • websites design & development
  • WP React
  • WP Security