問(wèn)題描述
在 Woocommerce 中,我們?cè)噲D在通過(guò) Paypal 支付網(wǎng)關(guān)購(gòu)買的訂單中增加額外費(fèi)用.
In Woocommerce, we are trying to add an additional cost to the order when is purchased via Paypal payment gateway.
我們通過(guò)這種方式改變了發(fā)送到 Paypal 的價(jià)格:
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;
}
它有效,但問(wèn)題是在付款過(guò)程之后,這筆額外費(fèi)用不會(huì)反映在訂單和電子郵件通知中.
It works, but the problem is after the payment process, this additional cost is not reflected in Orders and email notifications.
這可以通過(guò)某種方式解決嗎?任何幫助表示贊賞.
Is this can be solved in some way? Any help is appreciated.
推薦答案
您最好根據(jù)支付網(wǎng)關(guān)(此處為您的 Paypal)添加費(fèi)用,如下所示:
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
}
代碼位于活動(dòng)子主題(或活動(dòng)主題)的 function.php 文件中.經(jīng)過(guò)測(cè)試和工作.
這篇關(guān)于Woocommerce 結(jié)帳頁(yè)面上的額外貝寶費(fèi)用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!