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

Related Posts


May 21, 2019

Magento 2.3.1: Everything you have to think about the Latest Release

Subsequent to seeing the major Magento 2.3.0 discharge in November 2018, we are all prepared up to start Magento 2.3.1! The Magento nerds were holding on to find the amazement that were in the store for them in Magento Open Source 2.3.1 and Magento Enterprise, and it’s out now on March 26, 2019. The most

February 12, 2019

What is GraphQL Js?

GraphQL is a language. On the off chance that we instruct it to a product application, that application will almost certainly definitively impart any information prerequisites to a backend information administration that additionally speaks GraphQL. To instruct an information administration to speak GraphQL, we have to execute a runtime layer and open it to the