Skip to content

Instantly share code, notes, and snippets.

@kloon
Last active November 26, 2020 02:21
Show Gist options
  • Save kloon/6305088 to your computer and use it in GitHub Desktop.
Save kloon/6305088 to your computer and use it in GitHub Desktop.
WooCommerce set tax exemption based on user role
<?php
add_filter( 'init', 'wc_tax_exempt_user_roles' );
function wc_tax_exempt_user_roles() {
if ( ! is_admin() ) {
global $woocommerce;
if ( current_user_can('wholesaler') || current_user_can('distributor') ) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}
}
}
?>
@ladnie
Copy link

ladnie commented May 9, 2014

Hello, this would be really useful, but it doesnt work for me. Im using woo 2.1.16. Should all catalog prices be displayed without tax?

@ladnie
Copy link

ladnie commented May 9, 2014

Sorry, it works. Just Dynamic Pricing still shows prices with tax - do you have any idea how to fix it?

@tremblayly
Copy link

Hi
I'm in Canada and we have two taxes (PST & GST) that could be exempt. Just looking at this code snippet, for customers that would either be exempt from all taxes (so zero rate including shipping) or customers that would be exempt from the PST tax only. Would I duplicate the code snippet above for both tax classes I created? Do I also need to create two customer tax exempt and PST exempt user roles?
Thank you

@mdorchain
Copy link

This snippet won't work in your use case. You should take a look into the tax classes instead and define rules based on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment