WooCommerce - hide payment gateway

岁酱吖の 提交于 2019-12-06 15:03:00

I hope this will work for you , if any problem persist please let me know.

   function woo_disable_cod( $available_gateways ) {
        $current_user = wp_get_current_user();
        //check whether the avaiable payment gateways have Cash on delivery and user is not logged in or he is a user with role customer
        if ( isset($available_gateways['cod']) && ((current_user_can('customer') && $current_user->user_firstname == 'Peter' ) || ! is_user_logged_in() ) ) {

            //remove the paypal payment gateway from the available gateways.

             unset($available_gateways['paypal']);
         }
         return $available_gateways;
    }

    add_filter('woocommerce_available_payment_gateways', 'woo_disable_cod', 99, 1);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!