Disable WooCommerce Payment methods based on cart item quantity

 In Web Design, woocommerce web design and development, Wordpress Web Design

Disable WooCommerce Payment methods based on cart item quantity

To disable WooCommerce Payment methods based on cart item quantity, you need to simply copy and paste the following code in your theme’s functions.php file.

Here I’m unsetting the COD when cart item quantity limit reached 10.

add_filter(‘woocommerce_available_payment_gateways’, ‘disable_payment_gateway_based_on_quantity’, 10, 1);

function disable_payment_gateway_based_on_quantity( $available_gateways )
{
$qty_limit = 10;
$limit_reached = false;
foreach(WC()->cart->get_cart() as $cart_item){
if($cart_item[‘quantity’] > $qty_limit ){
$limit_reached = true;
break;
}
}
if($limit_reached){
unset($available_gateways[‘cod’]);
}
return $available_gateways;
}

 

You can use the same code Change quantity and payment method slug for your needs.

Recent Posts

Leave a Comment

thirteen + nineteen =

Start typing and press Enter to search

Steps to Remove Malware from Your WordPress SiteRedirect non admin users to home page and disallow back end access in WordPress