Skip to main content

Ⓒ Sales Tax USA.
All Rights Reserved.

#Thoughts

How to charge tax in only one state (Sales Tax Nexus setup)

Sean OBrien Jan 10, 2024
How to charge tax in only one state (Sales Tax Nexus setup)

Do you have a Sales Tax Nexus in only one state? Are you painstakingly removing all the other 49 states’ rates out of our WooCommerce Sales Tax CSV? It’s quite common for many of our customers, so now we’ve put together a simple method to help you speed up this process and make charging sales tax in only one state a breeze!

The below WooCommerce code snippet, which can be added to your theme (or child theme’s) functions.php file,  will apply sales tax exclusively to customers in the state you specify, and leave all other state’s using the “Zero Rate” tax class. It’s a useful customization for businesses that have tax obligations only in one state. It also simplies the process of using our WooCommerce CSV by ending the need to edit the file to remove states you don’t want to charge tax in.

This snippet will:
Check if the shipping state of the customer is not the specified state. If so, it sets the tax class to ‘Zero Rate’, effectively applying no tax. Otherwise, the default tax class is used, which is set by our CSV.

Example Situation

Your business is in New York and you have a tax nexus in New York (NY). You are not required to charge sales tax for other states, even though you sell to other states. Upload our CSV file as normal with all state’s rates included, then add the snippet below to your functions.php and include “NY” as the state to charge tax in. Customers with NY addresses will be charged sales tax and customers not from NY will be charged 0.000% (zero rate) sales tax.

In the below snippet, change “NY” to whichever state you require to have taxes applied

/**
 * CHARGE TAX ONLY FOR NY CUSTOMERS
 */

// Apply a custom tax class for customers in New York State
add_filter( 'woocommerce_product_tax_class', 'custom_tax_class_for_newyork', 1, 2 );
function custom_tax_class_for_newyork( $tax_class, $product ) {
    if ( WC()->customer->get_shipping_state() != 'NY' ) {
        return 'Zero Rate';
    }
    return $tax_class;
}

// Adjust tax rates based on customer's shipping state
add_filter( 'woocommerce_matched_rates', 'adjust_tax_rates_for_newyork', 10, 2 );
function adjust_tax_rates_for_newyork( $rates, $tax_class ) {
    if ( WC()->customer->get_shipping_state() != 'NY' ) {
        return []; // Return an empty array to indicate no tax for customers outside NY
    }
    return $rates; // Return the default rates for customers in NY
}

Always make sure to make a backup of your functions.php file before making any changes.

Leave a Reply