Last active
August 21, 2021 04:57
-
-
Save bagerathan/a5e4bca4a81857444ee0da421f72017e to your computer and use it in GitHub Desktop.
[Change tax amount based on billing or shipping address] #woo
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
billing_wcj_checkout_field_1 | |
<?php | |
add_action('woocommerce_after_checkout_form', function($checkout){ | |
?> | |
<script type="text/javascript"> | |
jQuery(function($){ | |
$(document).on('change','#billing_wcj_checkout_field_1',function(){ | |
$(document.body).trigger("update_checkout"); | |
}); | |
}); | |
</script> | |
<?php | |
}); | |
add_action( 'woocommerce_checkout_update_order_review', 'tilfrisoren_user_tax_exempt_callback', 10, 1 ); | |
function tilfrisoren_user_tax_exempt_callback( $post_data ) { | |
parse_str($post_data, $results); | |
extract($results); | |
$customer = WC()->customer; | |
if ( ! empty($billing_wcj_checkout_field_1) && $billing_country === 'NO' && ! $customer->is_vat_exempt() ) { | |
$customer->set_is_vat_exempt( true ); | |
} | |
elseif( ! empty($billing_wcj_checkout_field_1) && $billing_country === 'SE' && ! $customer->is_vat_exempt() ){ | |
$customer->set_is_vat_exempt( true ); | |
} | |
elseif ( $customer->is_vat_exempt() ){ | |
$customer->set_is_vat_exempt( false ); | |
} | |
} | |
function tilfrisoren_user_tax_exempt_callback_everywhere($wc_tax_enabled) { | |
$cart = WC()->cart; | |
$customer = WC()->customer; | |
parse_str($post_data); | |
if ( ! empty($billing_wcj_checkout_field_1) && $billing_country === 'NO' && ! $customer->is_vat_exempt() ) { | |
$wc_tax_enabled = false; | |
} | |
if ( ! empty($billing_wcj_checkout_field_1) && $billing_country === 'SE' && ! $customer->is_vat_exempt() ) { | |
$wc_tax_enabled = false; | |
} | |
return $wc_tax_enabled; | |
} | |
add_filter( 'wc_tax_enabled', 'tilfrisoren_user_tax_exempt_callback_everywhere', 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment