wordpress 在WooCommerce中只允许BACS支付高价产品

h6my8fg2  于 11个月前  发布在  WordPress
关注(0)|答案(1)|浏览(131)

我想限制买家通过BACS支付只有高价值的项目,例如超过99.我想出了以下代码,但它不隐藏卡支付.我不知道如果card是正确的值在$available_gateways['card']的WooPayments -信用卡/借记卡方法?
如何纠正?

函数.php

//////////// Restrict payment option to be BACS for high value items
add_filter('woocommerce_available_payment_gateways', 'restrict_bacs_for_high_value_items', 99, 1);
function restrict_bacs_for_high_value_items( $available_gateways ) {
    global $product;

    if ( is_admin() ) return $available_gateways; // Only on frontend

    $product_price = round($product->price);

    if ( isset($available_gateways['card']) && ($product_price > 99) ) {
        unset($available_gateways['card']);
    }
    return $available_gateways;
}

字符串

k5hmc34c

k5hmc34c1#

以下代码将仅在购物车中有高价值物品 (价格高达100的产品) 时将付款方式限制为BACS (银行电汇)

add_filter('woocommerce_available_payment_gateways', 'restrict_bacs_for_high_value_items', 99, 1);
function restrict_bacs_for_high_value_items( $available_gateways ) {
    // Only on frontend and if BACS payment method is enabled
    if ( ! is_admin() && isset($available_gateways['bacs']) ) {
        // Loop through cart items
        foreach ( WC()->cart->get_cart() as $item ) {
            // If an item has a price up to 100
            if ( $item['data']->get_price() >= 100 ) {
                // Only BACS payment allowed
                return ['bacs' => $available_gateways['bacs']]; 
            }
        }
    }
    return $available_gateways;
}

字符串
代码放在你的子主题的functions.php文件中(或插件中)。测试和工作。

相关问题