【发布时间】:2017-10-20 20:10:52
【问题描述】:
当在指定国家/地区的结帐页面上选择 PayPal 时,此代码会增加 29 的费用。但是,它没有被征税。现在的总税额是基于物品+运费。
如何在不向人们双重征税的情况下将税款添加到海关费用中?
这是我的代码:
function woocommerce_custom_fee( ) {
global $woocommerce;
$county = array('SE');
if ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) || ! is_checkout() )
return;
$chosen_gateway = $woocommerce->session->chosen_payment_method ;
$fee = 29;
if ( $chosen_gateway == 'paypal' and ( in_array( WC()->customer->get_shipping_country(), $county ) ) ) { //test with paypal method
$woocommerce->cart->add_fee( 'Paypal Avgift', $fee, false, '' );
}
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_fee' );
function cart_update_script() {
if (is_checkout()) :
?>
<script>
jQuery( function( $ ) {
// woocommerce_params is required to continue, ensure the object exists
if ( typeof woocommerce_params === 'undefined' ) {
return false;
}
$checkout_form = $( 'form.checkout' );
$checkout_form.on( 'change', 'input[name="payment_method"]', function() {
$checkout_form.trigger( 'update' );
});
});
</script>
<?php
endif;
}
add_action( 'wp_footer', 'cart_update_script', 999 );
谢谢
【问题讨论】:
-
你打算如何计算税收?你有现成的配方吗?
-
@OluwafemiSule 我尝试使用
$total_taxes = array_sum($woocommerce->cart->get_taxes());,但没有帮助。我不确定我是否正确使用它。花了我一整天才让主要代码工作(我在 3 周前开始使用 PHP) -
[$woocommerce->cart->get_cart_tax][docs.woocommerce.com/wc-apidocs/… 返回购物车中所有商品的总税款。我的问题是,您认为目前没有对购物车征税吗?
-
@ErikaJohansson ...没问题,我们都像你一样经历过这个。在您未来的问题中,不要忘记提及您正在使用 Klarna 插件并提供有关...的最大详细信息
标签: php wordpress woocommerce payment-gateway checkout