Php Woocommerce结账页面上的额外paypal费用
在Woocommerce中,当通过Paypal支付网关购买时,我们试图为订单增加额外成本 我们这样做是为了改变发送给贝宝的价格:Php Woocommerce结账页面上的额外paypal费用,php,jquery,wordpress,paypal,woocommerce,Php,Jquery,Wordpress,Paypal,Woocommerce,在Woocommerce中,当通过Paypal支付网关购买时,我们试图为订单增加额外成本 我们这样做是为了改变发送给贝宝的价格: 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;
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;
}
这是可行的,但问题是在支付过程之后,订单和电子邮件通知中没有反映出这一额外成本
这能以某种方式解决吗?非常感谢您的帮助。您最好根据支付网关(此处为您的Paypal)添加费用,如下所示:
// 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
}
//选择Paypal时增加10.00的费用
添加操作('woocommerce\u cart\u calculate\u fees'、'custom\u paypal\u additional\u fees',20,1);
功能自定义\贝宝\附加\费用($cart){
if(定义了('DOING'uajax'))
返回;
如果(WC()->session->get('selected\u payment\u method')=='paypal')
$cart->add_-fee(uuu('Paypal-fee','woocommerce'),10.00);
}
//添加有关签出paypal文本网关部分的信息
添加过滤器(“woocommerce\u gateway\u图标”、“自定义\u paypal\u gateway\u文本”,20,2);
函数自定义\ paypal \网关\文本($html、$gateway\ id){
如果($gateway_id=='paypal')
$html.='(+'.wc_价格(10.00)。);
返回$html;
}
//选择网关刷新费用时启用ajax更新签出事件
添加操作(“工作包页脚”、“付款网关”、“更新”、“签出事件”);
功能支付\网关\更新\签出\事件(){
?>
(函数($){
$('form.checkout')。在('change','input[name^=“payment_method”]”上,函数(){
var t={UpdateTime:!1,dirtyInput:!1,
重置\更新\签出\计时器:函数(){
clearTimeout(t.updateTimer)
},触发器\更新\签出:函数(){
t、 重置\更新\签出\计时器(),t.dirtyInput=!1,
$(document.body).trigger(“update\u checkout”)
}
};
$(document.body).trigger('update\u checkout')
});
})(jQuery);