Woocommerce 结帐页面上的额外贝宝费用

Additional paypal fee on Woocommerce checkout page(Woocommerce 结帐页面上的额外贝宝费用)
本文介绍了Woocommerce 结帐页面上的额外贝宝费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 Woocommerce 中,我们试图在通过 Paypal 支付网关购买的订单中增加额外费用.

In Woocommerce, we are trying to add an additional cost to the order when is purchased via Paypal payment gateway.

我们通过这种方式改变了发送到 Paypal 的价格:

We did it changing the price that is sent to Paypal this way:

add_filter('woocommerce_paypal_args', 'addition_pay');

function addition_pay($paypal_args){
        $new_value=$paypal_args['amount_1']+10;
        $paypal_args['amount_1']=$new_value;
        return $paypal_args;
} 

它有效,但问题是在付款过程之后,这笔额外费用不会反映在订单和电子邮件通知中.

It works, but the problem is after the payment process, this additional cost is not reflected in Orders and email notifications.

这可以通过某种方式解决吗?任何帮助表示赞赏.

Is this can be solved in some way? Any help is appreciated.

推荐答案

您最好根据支付网关(此处为您的 Paypal)添加费用,如下所示:

You should better add a fee based on payment gateway (here Paypal for you), like in the following:

// Add a fee of 10.00 when Paypal is chosen
add_action( 'woocommerce_cart_calculate_fees', 'custom_paypal_additional_fee', 20, 1 );
function custom_paypal_additional_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if( WC()->session->get( 'chosen_payment_method' ) == 'paypal' )
        $cart->add_fee( __( 'Paypal fee', 'woocommerce' ), 10.00 );
}

// Add the information on checkout paypal text gateways section
add_filter('woocommerce_gateway_icon', 'custom_paypal_gateway_text', 20, 2 );
function custom_paypal_gateway_text( $html, $gateway_id ) {
    if( $gateway_id == 'paypal' )
        $html .= ' <small class="paypal-fee">(+ '.wc_price(10.00).')</small>';

    return $html;
}

// Enable ajax update checkout event when choosing a gateway to refresh the fee
add_action('wp_footer', 'payment_gateways_update_checkout_event' );
function payment_gateways_update_checkout_event() {
    ?>
    <script type="text/javascript">
        (function($){
            $('form.checkout').on( 'change', 'input[name^="payment_method"]', function() {
                var t = { updateTimer: !1,  dirtyInput: !1,
                    reset_update_checkout_timer: function() {
                        clearTimeout(t.updateTimer)
                    },  trigger_update_checkout: function() {
                        t.reset_update_checkout_timer(), t.dirtyInput = !1,
                        $(document.body).trigger("update_checkout")
                    }
                };
                $(document.body).trigger('update_checkout')
            });
        })(jQuery);
    </script>
    <?php
}

代码位于活动子主题(或活动主题)的 function.php 文件中.经过测试和工作.

这篇关于Woocommerce 结帐页面上的额外贝宝费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)