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


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

February 1, 2019

Magento 2.x mail sent from unknown host name

If you are using Magento 2.2.4 or higher, either fresh or upgrade from 2.2.3, there is a bug that alters the email sender name. It will change from your presence in the store configuration General->Store Email Address to the server usernames. Something like this: 2.2.3 – salesteam@ikodes.net 2.2.4 – serverusername@myserver.ikdoes.net or on Stratus this might