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 for disable WooCommerce Payment methods based on cart item quantity. Change quantity and payment method slug for your needs.

Have any doubt, then comment here!

Leave a Reply

Your email address will not be published. Required fields are marked *