Search code examples
phpwordpresswoocommercehook-woocommercedokan

How to disable Cash On Delivery for dokan vendors subscription


I am using WooCommerce Dokan (Version 3.2.6 ) multi-vendor plugin. In my website Cash on delivery and pay by card both methods are enable for users. But when any vendor purchasing a package, it is showing Cash On Delivey for that as well, due to which I have to keep track of every vendor manually whether he has paid or not.

I want to disable COD for vendors and enable for users only.

enter image description here


Solution

  • Just came across your question and decided to add the answer for future reference!

    So, for disabling the cash on delivery option only for sellers/vendors not normal users, you could use:

    • woocommerce_available_payment_gateways filter hook.

    And

    • dokan_is_user_seller and dokan_get_current_user_id functions to check whether the buyer is a seller or a normal user!

    Use the following code in your functions.php file:

    add_filter(
        'woocommerce_available_payment_gateways', 'disabling_cod_for_sellers', 999);
    
    function disabling_cod_for_sellers($available_payment_gateways)
    {
        if (
            dokan_is_user_seller(dokan_get_current_user_id())
            &&
            isset($available_payment_gateways['cod'])
           ) 
        {
            unset($available_payment_gateways['cod']);
        }
        return $available_payment_gateways;
    }
    

    This answer has been tested on Dokan 3.3.5, Woo 5.7 and works.