This code adds a fee of 29 when PayPal is selected on checkout page for a defined country. However, it's not being taxed. The total tax right now is based on items + shipping.
How would I go about to add tax to the custom fee without double taxing people?
This is my code:
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 );
Thanks