WooCommerce - 隐藏支付网关

问题描述 投票:1回答:1

如何在WooCommerce上为特定客户隐藏支付网关插件,例如,如果客户的名字是:Peter,该插件将不会为他显示。

例如:Woocommerce hide payment gateway for user roles

php wordpress woocommerce hide payment
1个回答
2
投票

我希望这对你有用,如果有任何问题仍然存在,请告诉我。

   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);
© www.soinside.com 2019 - 2024. All rights reserved.