Back to Community

How to Check and Modify Applied Taxes in WooCommerce

14 threads Sep 7, 2025 PluginWoocommerce

Content

Working with taxes is a common challenge for WooCommerce store owners, especially when you need to check which taxes are applied to an order or modify how they are displayed. This guide covers the most common methods for programmatically checking applied taxes and customizing tax-related text throughout your store.

Why Check Applied Taxes Programmatically?

There are several scenarios where you might need to check which taxes are being applied to a cart or order:

  • Applying conditional fees based on specific taxes (e.g., adding a handling fee if Duty or GST is applied)
  • Running custom reports or calculations based on tax types
  • Implementing custom tax exemption logic for specific user groups

How to Check for Specific Taxes on the Checkout Page

To check if a specific tax is being applied during checkout, you can use WooCommerce's get_tax_totals() method. This function returns an array of all tax items applied to the current cart. Here's a practical example that checks for a "Duty" tax:

// Hook into cart fee calculation
add_action( 'woocommerce_cart_calculate_fees', 'check_for_duty_tax' );

function check_for_duty_tax( $cart ) {
    // Get all applied tax items
    $tax_totals = $cart->get_tax_totals();
    $duty_exists = false;
    
    // Check each tax item
    foreach ( $tax_totals as $tax ) {
        // Compare tax label (case-sensitive exact match)
        if ( 'Duty' === $tax->label ) {
            $duty_exists = true;
            break;
        }
    }
    
    // If duty tax exists, apply custom fee
    if ( $duty_exists ) {
        $cart->add_fee( 'Duty Handling Fee', 5.00 );
    }
}

This code snippet hooks into the woocommerce_cart_calculate_fees action, retrieves all tax totals, checks if a tax with the label "Duty" exists, and applies a custom fee if it does.

Customizing Tax Display Text

If you need to change how tax information is displayed (for example, changing "Tax" to "GST" in emails, invoices, and order notifications), you have several options:

Method 1: Using a Gettext Filter

The most flexible approach is to use WordPress's gettext filter to dynamically replace text:

add_filter( 'gettext', 'change_tax_text_to_gst', 20, 3 );

function change_tax_text_to_gst( $translated_text, $text, $domain ) {
    if ( $domain === 'woocommerce' ) {
        if ( $text === 'incl. tax' ) {
            $translated_text = 'incl. GST';
        } elseif ( $text === 'Tax' ) {
            $translated_text = 'GST';
        }
    }
    return $translated_text;
}

Method 2: Using the Loco Translate Plugin

For a non-code solution, you can use the Loco Translate plugin to find and replace tax-related text throughout WooCommerce without modifying theme files.

Method 3: Naming Your Tax Class

In some cases, simply naming your tax class "GST" in WooCommerce > Settings > Tax will automatically update how it's displayed throughout your store.

Working with Tax Exemption

For stores that need to handle tax-exempt customers, WooCommerce uses the is_vat_exempt order meta field. When set to "yes," this field prevents tax calculation for that order.

To automatically set tax exemption for specific users, you would need to:

  1. Add a custom user meta field to identify tax-exempt users
  2. Hook into the checkout process to automatically set is_vat_exempt to "yes" for marked users

Important Considerations

  • Tax checking code should be added to your theme's functions.php file or a custom plugin
  • Always test tax modifications on a staging site before implementing on your live store
  • Be aware that some tax-related functionality may vary depending on your theme and other plugins
  • The methods described here work with standard WooCommerce tax functionality but may need adjustment for complex tax scenarios

By understanding these techniques for checking and modifying tax information, you can create more customized shopping experiences and better meet your business requirements for tax handling and display.

Related Support Threads Support