如果 WooCommerce 中的购物车总数为 0,则付款方式不显示

Payment methods not showing if cart total is 0 in WooCommerce

我正在为具有多个用户角色的客户设置商店。其中之一的价格需要为 0 美元,因为该公司按月计费。其他角色必须使用“按用户角色划分的产品价格”根据他们的角色支付不同的乘数价格。

无论如何,当用户以 0 美元购买某些产品时,COD 方法未显示,我需要该支付网关来设置自定义状态。

以前有人遇到过这个问题吗?如果遇到过,欢迎任何指导!

“以前有人遇到过这个问题吗?”这是 WooCommerce 中的默认行为

要防止这种情况,请使用:

// Looks at the totals to see if payment is actually required.
function filter_woocommerce_cart_needs_payment( $needs_payment, $cart ) {
    // Set true
    $needs_payment = true;
    
    return $needs_payment;
}
add_filter( 'woocommerce_cart_needs_payment', 'filter_woocommerce_cart_needs_payment', 10, 2 );

或者简而言之

add_filter( 'woocommerce_cart_needs_payment', '__return_true' );

// Checks if an order needs payment, based on status and order total.
function filter_woocommerce_order_needs_payment( $needs_payment, $order, $valid_order_statuses ) {  
    // Set true
    $needs_payment = true;

    return $needs_payment;
}
add_filter( 'woocommerce_order_needs_payment', 'filter_woocommerce_order_needs_payment', 10, 3 );

或者简而言之

add_filter( 'woocommerce_order_needs_payment', '__return_true' );