Disable Payment Method for Specific Category In WooCommerce

 In woocommerce web design and development

Disable Payment Method for Specific Category In WooCommerce

we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if certain product categories are in the cart. Disable Payment Method for Specific Category In WooCommerce.

Woocommerce web design company in chennai

Woocommerce web design company in chennai

Disable Payment Method for Specific Category

/**
* @snippet Disable Payment Method for Specific Category
* @testedwith WooCommerce 3.3.4
*/

add_filter( ‘woocommerce_available_payment_gateways’, ‘bbloomer_unset_gateway_by_category’ );

function bbloomer_unset_gateway_by_category( $available_gateways ) {
global $woocommerce;
$unset = false;
$category_ids = array( 8, 37 );
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;
}

Where can i add this code

You can place PHP snippets at the bottom of your child theme functions.php file (before “?>” if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files.

Recent Posts

Leave a Comment

two × one =

Start typing and press Enter to search

Dynamic Web Design Companyecommerce-trends-2018-india-web-creators