Add Ability to Remove Taxes for Logged in Wholesale Orders
This would probable be an add on to the Dynamic Pricing Plugin I would think but maybe not. I need the ability to not charge tax to logged in wholesaler users. This is extremely important for one of my clients that I am building a site for, if I can this this functionality this plugin will be exactly what i need.
Thanks!
Daniel
6 comments
-
Luke Cavanagh commented
-
Conrad commented
I am getting an error when non-logged in customers try to make purchases,
"Fatal error: Allowed memory size of 98566144 bytes exhausted (tried to allocate 75 bytes) in /home/wash/public_html/site2/wp-includes/functions.php on line 2625"
Would this be because of this ability I added? How can I make it so there is no error for customers with no assigned role.
-
Anonymous commented
I agree this is a much needed function for the Dynamic Pricing Plugin. Unfortunately, my groups are more extensive then just "wholesale" and having the updates override the change is a hassle, so customizing the code with the link below is not optimal. Please consider adding this feature.
-
Daniel Nice commented
To handle muiltiple auruments it would be something like this.
if(get_user_role()=='wholesaler' || get_user_role()=='government'){
you could also use a case statement instead of an if if you wanted or even do something like
if(get_user_role()!='customer'){
which will apply the rule to any role that is not customer
-
Conrad commented
to apply this to multiple rules can i just use a comma like
if (get_user_role()=='wholesaler,government') {
or how do I handle that? Thanks
-
Daniel Nice commented
An update on this one, you can hack the core code to get this to work but note that a WooCommerce update will likely break or overwrite these changes. You have been warned :-)
In the class-wc-tax.php edit line 522 by default it shoudl look something like this:
function get_tax_total( $taxes ) {
return array_sum(array_map(array(&$this, 'round'), $taxes));
}It should look something like this
function get_tax_total( $taxes ) {
if (get_user_role()=='wholesaler') {
return 0;
} else {
return array_sum(array_map(array(&$this, 'round'), $taxes));
}
}I also added the get_user_role() function to my functions.php that code is below.
function get_user_role() {
global $current_user;$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);return $user_role;
}I hope this helps someone, this solved my issue, at least for the time being. This code removes the tax from the logged in user role of "wholesaler"