WooCommerce 中购物车总数是否为 0 时付款方式未显示

时间:2021-06-02 09:15:01

标签: wordpress woocommerce cart hook-woocommerce payment-method

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

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

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

1 个答案:

答案 0 :(得分:1)

“有人遇到过这个问题吗?”这是 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' );