【问题标题】:WooCommerce - hide payment gatewayWooCommerce - 隐藏支付网关
【发布时间】:2016-02-09 20:42:00
【问题描述】:

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

例如: Woocommerce hide payment gateway for user roles

【问题讨论】:

    标签: php wordpress woocommerce hide payment


    【解决方案1】:

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

       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);
    

    【讨论】:

    • 感谢 Prafulla 的回复,不幸的是它对我不起作用。我绑定编辑代码但没有结果。
    • 你能var_dump( $current_user );发布你得到了什么吗?
    • 这对我有用,只需要适当地调整条件以适应我的情况,代码是正确的。
    猜你喜欢
    • 2015-08-26
    • 2021-07-10
    • 2021-01-26
    • 2019-05-03
    • 2013-07-18
    • 1970-01-01
    • 2019-04-07
    • 2017-03-02
    • 2018-11-07
    相关资源
    最近更新 更多