WordPress Custom Functions For WooCommerce Taxes

There are so many functions that affect all aspects of WooCommerce defaults. Here’s one that we used to create a special tax rate that needed to be applied to a specific WordPress user role. For more information on using your theme’s function.php file, read this article first.

Apply A Different Tax Rate Based On User Role

While rare, there are times that you need to have a specific user role that has a different tax rate. Using the following function handles this very thing. This exact code is meant for a user role named “dealer” with a custom tax name of “My Special Rate”. Simply change these two values to meet your needs. For example, the name of your tax class might be “Reduced Rate” where the user pays half the amount of the normal tax class.

// Apply A Different Tax Rate Based On User Role
function wc_diff_rate_for_user( $tax_class, $product ) {
	if ( is_user_logged_in() && current_user_can( 'dealer' ) ) {
		$tax_class = 'My Special Rate';
	return $tax_class;
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );
Code Recipes, WooCommerce Functions, WooCommerce Tips, WordPress functions.php
Previous Post
Sorting Out of Stock WooCommerce Products Last with functions.php
Next Post
WordPress Custom Functions For WooCommerce Product Detail Page

Related Posts

You must be logged in to post a comment.