2016-07-14 223 views
2

我正在构建WooCommerce网站,我需要为特定支付网关应用自定义手续费。
我从这里有这段代码:How to Add Handling Fee to WooCommerce CheckoutWooCommerce:为现金付款方式(cod)添加费用

这是我的代码:

add_action('woocommerce_cart_calculate_fees','endo_handling_fee'); 
function endo_handling_fee() { 
    global $woocommerce; 

    if (is_admin() && ! defined('DOING_AJAX')) 
     return; 

     $fee = 5.00; 
    $woocommerce->cart->add_fee('Handling', $fee, true, 'standard'); 
} 

此功能的费用添加到所有交易

是否有可能tweek此功能,使其适用于现金只交货付款?

我会欢迎任何替代方法。我知道类似的“支付网关费用”woo插件,但我买不起。

谢谢。

+0

谢谢大家的反馈,我相应的更新 –

+0

坏消息......看到我的答案。对不起,你必须找到不同的东西。 – LoicTheAztec

回答

2

这是不可能的,对不起...

说明:

  • 的问题是,货到付款(COD)付款方式只在后车下一步可供选择:在结帐页面上。

  • 无法在购物车页面上设置或获取任何付款方式,因为您无法在结帐前知道客户将选择哪种付款方式。

此功能(您的代码)不能根据需要进行调整。

为此目的将是必要的负荷消费选择购物车页面上的付款方式是什么绝对不是WooCommerce behavio

0

对于其他人要做到这一点,我想补充的银行转账手续费(BACS),这里是我使用的方法:

//Hook the order creation since it is called during the checkout process: 
add_filter('woocommerce_create_order', 'my_handle_bacs', 10, 2); 

function my_handle_bacs($order_id, $checkout){ 
//Get the payment method from the $_POST 
    $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : ''; 

//Make sure it's the right payment method 
    if($payment_method == "bacs"){ 

     //Use the cart API to add recalculate fees and totals, and hook the action to add our fee 
     add_action('woocommerce_cart_calculate_fees', 'my_add_bacs_fee'); 
     WC()->cart->calculate_fees(); 
     WC()->cart->calculate_totals(); 
    } 

    //This filter is for creating your own orders, we don't want to do that so return the $order_id untouched 
    return $order_id; 
} 
function my_add_bacs_fee($cart){ 
    //Add the appropriate fee to the cart 
    $cart->add_fee("Bank Transfer Fee", 40); 
}