wordpress 隐藏WooCommerce BACS付款,如果购物车总数小于特定金额

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

我试图隐藏银行转账付款方式时,订单是低于500美元,但代码是不工作。你能帮我找到错误?

add_filter( 'woocommerce_available_payment_gateways', 'show_hide_payment_methods_on_checkout' , 1 );

function show_hide_payment_methods_on_checkout( $available_gateways ) {
    // Set minimum cart total
    $minimum_order_total = 500;

    // Get the order total
    $order_total = WC()->cart->get_total( 'edit' );
    echo 'Final Price: ' . $order_total;
    // Check if the order total is less than or equal to the minimum
    if ( $order_total <= $minimum_order_total ) {
        // Check if 'bacs' payment gateway is available and unset it
        if ( isset( $available_gateways['bacs'] ) ) {
            unset( $available_gateways['bacs'] );
        }
    }

    return $available_gateways;
}

字符串

mzaanser

mzaanser1#

请尝试以下操作:

add_filter( 'woocommerce_available_payment_gateways', 'show_hide_bacs_payment_gateway' );
function show_hide_bacs_payment_gateway( $available_gateways ) {
    // Only on checkout page
    if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) )
        return $available_gateways;

    // Set the targeted cart total
    $targeted_total = 500;

    // Check if the order total is less than or equal to the minimum for BACS payment
    if ( WC()->cart->total <= $targeted_total && isset($available_gateways['bacs']) ) {
        unset($available_gateways['bacs']);
    }
    return $available_gateways;
}

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

相关问题