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


why-you-should-use-wordpress-as-a-beginner-hire-wordpress-developer

January 19, 2020

Why You Should Use WordPress as a Beginner

Along these lines, you plan on beginning another blog for yourself. There are several alternatives accessible for you to do as such. Nonetheless, still, a great many people disregard these alternatives and straightaway go for WordPress. All in all, what makes WordPress so prominent? Here are 15 extraordinary reasons why you ought to consider WordPress

January 18, 2020

Top 5 Hybrid Mobile App Frameworks for 2018

The fight between Best Hybrid Mobile App Frameworks in 2018 and top local app system is an endless one; both have their own advantages and disadvantages. While serving different customers from new businesses to ventures, one thing I learned is that picking among local and hybrid app advancement isn’t a simple errand. Everything relies upon