2016-07-14 18 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、それが唯一の配達の支払いに現金のために適用することが可能ですか?

いずれの代替方法も歓迎します。私は同様の "Payment Gateway Based Fees"のプラグインについて知っていますが、余裕がありません。

ありがとうございました。

+0

は、私はそれに応じて更新し、フィードバックをありがとう –

+0

悪いニュース...私の答えを見てください。申し訳ありませんが、別のものを見つける必要があります。 – LoicTheAztec

答えて

2

これは不可能です、申し訳ありません...

説明:

  • 問題が代金現金(代金引換)支払方法がカートの後に次のステップでのみ利用可能であるということです。チェックアウトページ。

  • カート・ページで支払い方法を設定または取得することはできません。これは、お支払い前に、どのお支払い方法が代金者によって選択されるかを知ることができないためです。

この機能(あなたのコード)は、あなたが望むように調整することはできません。そのために

衣装が絶対にWooCommerceは Rを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); 
} 
関連する問題