Woocommerce 隐藏用户角色的支付网关 [英] Woocommerce hide payment gateway for user roles

查看:30
本文介绍了Woocommerce 隐藏用户角色的支付网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我在我的 wordpress/woocomerce 网站上有一种货到付款付款方式,我想对客户用户角色和非登录用户隐藏.

Hey guys I have a cash on delivery payment method on my wordpress/woocomerce website that I want to hide from the customer user role and non-logged in users.

我一直在上下搜索,我发现唯一接近的是这段代码.

I've been searching up and down and the only thing I found close was this bit of code.

function paypal_disable_manager( $available_gateways ) 

{global $woocommerce;

if ( isset( $available_gateways['paypal'] ) && current_user_can('customer') ) {

unset( $available_gateways['paypal'] );

}

return $available_gateways;

}

add_filter( 'woocommerce_available_payment_gateways','paypal_disable_manager' );

有人能帮我修改这段代码,让它为我所用.提前致谢!

Would someone be able to help me modify this code to make it work for my use. Thank you in advance!

推荐答案

提到了为你尝试和测试过的代码.它运作良好.让我知道这是否也适用于您.

Have mention the code which is tried and tested for you. It works well. Lemme know if the same works for you too.

function wdm_disable_cod( $available_gateways ) {

    //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') || ! is_user_logged_in()) ) {

        //remove the cash on delivery payment gateway from the available gateways.

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

add_filter('woocommerce_available_payment_gateways', 'wdm_disable_cod', 99, 1);

这篇关于Woocommerce 隐藏用户角色的支付网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆