Last active
May 3, 2019 09:29
-
-
Save vagelisp/0bbef460ca3ec243afdb91ebf5fbbc31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_cart_calculate_fees','custom_tax_surcharge_for_retailers', 10, 1 ); | |
function custom_tax_surcharge_for_retailers( $cart ) { | |
if ( is_admin() && ! defined('DOING_AJAX') ) return; | |
global $woocommerce; | |
if ( isset( $_POST['post_data'] ) ) { | |
parse_str( $_POST['post_data'], $post_data ); | |
} else { | |
$post_data = $_POST; | |
} | |
if ( 'AT' == WC()->customer->get_billing_country() OR $post_data['billing_user'] == 'Ιδιώτης' ) { | |
$percent = 20; | |
// Calculation | |
$surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percent / 100; | |
// Add the fee (tax third argument disabled: false) | |
$cart->add_fee( __( 'ΦΠΑ', 'woocommerce')." ($percent%)", $surcharge, false ); | |
} | |
} | |
add_action( 'wp_footer', 'woocommerce_fieldchange_bind' ); | |
function woocommerce_fieldchange_bind() { | |
if (is_checkout()) { | |
?> | |
<script type="text/javascript"> | |
jQuery( document ).ready(function( $ ) { | |
$('#select2-billing_country-container, CHANGEME').click(function(){ //Change CHANGEME to your field's identifier | |
jQuery('body').trigger('update_checkout'); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment