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


October 12, 2019

History of WordPress

Would you like to think about the historical backdrop of WordPress? On the off chance that you are beginning a WordPress blog or site today, at that point you see a prevalent web designer which fueled over 32% of all sites on the web. In this article, we need to investigate the historical backdrop of

October 12, 2019

What’s New in WordPress 5.2

WordPress 5.2 “Jaco” was authoritatively discharged on May 7, 2019, and is accessible for download. This variant comes pressed with a great deal of energizing changes, the greatest one being the new Site Health check apparatus which will enable both to instruct clients and give designers the basic data they need. Different enhancements incorporate PHP