久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Woocommerce 中為特定支付網關添加自定義費用

Add a custom fee for a specific payment gateway in Woocommerce(在 Woocommerce 中為特定支付網關添加自定義費用)
本文介紹了在 Woocommerce 中為特定支付網關添加自定義費用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在選擇付款方式(信用卡)時,如何在總金額中增加一個百分比?

How can I add a percentage to the total amount when choosing a payment (credit card)?

例如:如果客戶貨到付款,那么基價,如果我選擇在線支付,那么我收取的百分比加到總金額中?

For example: If the customer pays for cash on delivery, then the base price, and if I chose online payment, then the percentage charged by me is added to the total amount?

貨到付款的網關ID規定:cod在線支付網關ID設置:tinkoff

Gateway ID for cash payment on delivery is set out: cod Gateway ID for online payment is set out: tinkoff

add_action( 'woocommerce_after_calculate_totals', 'custom_fee_for_tinkoff' );

function custom_fee_for_tinkoff( $cart ) {

 if ( is_checkout() || defined('WOOCOMMERCE_CHECKOUT') ) {

  $payment_method = WC()->session->get( 'chosen_payment_method' );

   if ($payment_method == 'tinkoff') {
    $percentage = 0.025;
    $surcharge = ( $cart->cart_contents_total + $cart->tax_total ) * $percentage;

    $cart->add_fee( 'Комиссия банка', $surcharge, true, '' );
  }
   else { return; }
 }
}

有問題的圖片

推薦答案

嘗試使用以下重新訪問的代碼來代替它:

Try the following revisited code instead that should do the trick:

// Add a custom fee based o cart subtotal
add_action( 'woocommerce_cart_calculate_fees', 'custom_fee_for_tinkoff', 20, 1 );
function custom_fee_for_tinkoff ( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) )
        return; // Only checkout page

    $payment_method = WC()->session->get( 'chosen_payment_method' );

    if ( 'tinkoff' == $payment_method ) {
        $surcharge = $cart->subtotal * 0.025;
        $cart->add_fee( 'Комиссия банка', $surcharge, true );
    }
}

// jQuery - Update checkout on methode payment change  
add_action( 'wp_footer', 'custom_checkout_jqscript' );
function custom_checkout_jqscript() {
    if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) )
        return; // Only checkout page
    ?>
    <script type="text/javascript">
    jQuery( function($){
        $('form.checkout').on('change', 'input[name="payment_method"]', function(){
            $(document.body).trigger('update_checkout');
        });
    });
    </script>
    <?php
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經測試有效.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

這篇關于在 Woocommerce 中為特定支付網關添加自定義費用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 毛片一区 | 精品国产三级 | 国产精品揄拍一区二区 | 久久精品一区二区三区四区 | 亚洲风情在线观看 | 欧美国产精品 | 午夜欧美 | 亚洲午夜av | 91精品国产日韩91久久久久久 | 午夜激情免费视频 | 亚洲精品在线看 | 91xxx在线观看| 亚洲激情自拍偷拍 | 精品不卡 | 亚洲经典一区 | 欧美在线观看一区二区 | 国产区久久 | 在线一级片 | 日本在线你懂的 | 伊人免费网 | 亚洲电影第1页 | 精品国产一区二区在线 | 国产一级淫片免费视频 | 一区二区三区高清 | 国产成人精品久久二区二区91 | 亚洲视频中文字幕 | 免费av电影网站 | 黄色毛片免费视频 | 亚洲精品视频免费 | 欧美日韩中文字幕 | 美国一级毛片a | 久久精品在线播放 | 亚洲一区二区免费看 | 亚洲电影一区二区三区 | 免费视频一区 | 神马影院一区二区三区 | 免费黄视频网站 | 综合一区二区三区 | 二区三区视频 | 99福利在线观看 | 美女亚洲一区 |