WooCommerce: Simple Price Including/Excluding Tax Switcher

In WooCommerce, you can choose whether to display product prices including or excluding tax—but this setting is usually fixed site-wide, controlled by the admin. For stores serving both B2B and B2C customers, or international buyers, it can be confusing when visitors aren’t sure which price they’re seeing. Some customers prefer to see the final price with tax included, while others want to compare net prices.

What if you could give your shoppers the freedom to switch between the two views on the frontend? A simple toggle, checkbox or dropdown can make your store more transparent and improve user experience.

In this tutorial, we’ll show you how to implement a lightweight “Price Display Switcher” in WooCommerce. This solution respects your existing tax settings, remembers the user’s choice, and works across product pages, shop pages, and the cart.

You’ll get a working setup with minimal code, no heavy plugins, and a clean, native interface.

On load, my tax switcher displays prices according to the default store tax settings. My shortcode is selected with the default choice.
As soon as I change the selection, page reloads and prices are now including tax! The cart is also updated.

PHP Snippet: Add a Frontend Dropdown to Switch WooCommerce Inc/Ex Tax Prices

This WooCommerce customization allows customers to toggle between viewing prices with or without tax included. It uses cookies to remember each visitor’s preference across page visits. The system overrides the default shop tax display settings based on user choice, and provides a dropdown shortcode that can be placed anywhere on the site:

[bbloomer_tax_toggle]

Here’s a breakdown of how each function works together to create this tax display toggle system:

bbloomer_handle_tax_display_toggle

This function runs on every page load and checks if someone clicked the dropdown to change their tax preference. When it detects the URL parameter “toggle_tax_display”, it saves the user’s choice (either “incl” or “excl”) in a cookie that lasts for one month. The cookie remembers whether they want to see prices with or without tax.

bbloomer_filter_shop_tax_display and bbloomer_filter_cart_tax_display

These two functions intercept WooCommerce’s tax display settings. Instead of using the default shop settings, they check if the user has a preference saved in their cookie. If the cookie exists, they force WooCommerce to display prices according to the user’s choice, overriding the admin settings.

bbloomer_tax_toggle_shortcode

This creates the dropdown selector that users see on the page. It reads the current preference from the cookie (or uses the default if no cookie exists) and displays a dropdown with two options showing localized tax labels like “Incl. VAT” or “Excl. VAT”.

bbloomer_tax_toggle_script

This adds JavaScript that listens for dropdown changes. When someone selects a different option, it reloads the page with the appropriate URL parameter, triggering the first function to save their new preference.

/**
 * @snippet       Frontend WooCommerce Tax Toggle Shortcode
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 10
 * @community     Join https://businessbloomer.com/club/
 */

// Handle tax display preference via cookie
add_action( 'init', 'bbloomer_handle_tax_display_toggle' );
function bbloomer_handle_tax_display_toggle() {
    if ( isset( $_GET['toggle_tax_display'] ) ) {
        $pref = sanitize_text_field( $_GET['toggle_tax_display'] );
        if ( in_array( $pref, array( 'incl', 'excl' ), true ) ) {
            setcookie( 'bb_tax_display', $pref, time() + MONTH_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
            $_COOKIE['bb_tax_display'] = $pref;
        }
    }
}

// Filter shop tax display based on cookie
add_filter( 'pre_option_woocommerce_tax_display_shop', 'bbloomer_filter_shop_tax_display' );
function bbloomer_filter_shop_tax_display( $value ) {
    if ( isset( $_COOKIE['bb_tax_display'] ) ) {
        return $_COOKIE['bb_tax_display'] === 'incl' ? 'incl' : 'excl';
    }
    return $value;
}

// Filter cart tax display based on cookie
add_filter( 'pre_option_woocommerce_tax_display_cart', 'bbloomer_filter_cart_tax_display' );
function bbloomer_filter_cart_tax_display( $value ) {
    if ( isset( $_COOKIE['bb_tax_display'] ) ) {
        return $_COOKIE['bb_tax_display'] === 'incl' ? 'incl' : 'excl';
    }
    return $value;
}

// Shortcode for tax display dropdown
add_shortcode( 'bbloomer_tax_toggle', 'bbloomer_tax_toggle_shortcode' );
function bbloomer_tax_toggle_shortcode() {
    $default = get_option( 'woocommerce_tax_display_shop' );
    $current = $_COOKIE['bb_tax_display'] ?? $default;    
    ob_start();
    ?>
    <div class="bb-tax-toggle">        
        <select id="bb-tax-select">
            <option value="incl" <?php selected( $current, 'incl' ); ?>>
                <?php echo WC()->countries->inc_tax_or_vat(); ?>
            </option>
            <option value="excl" <?php selected( $current, 'excl' ); ?>>
                <?php echo WC()->countries->ex_tax_or_vat(); ?>
            </option>
        </select>
    </div>
    <?php
    return ob_get_clean();
}

// Add JavaScript for page reload
add_action( 'wp_footer', 'bbloomer_tax_toggle_script' );
function bbloomer_tax_toggle_script() { ?>
<script>
document.getElementById('bb-tax-select')
  ?.addEventListener('change', function() {
      window.location = '?toggle_tax_display=' + this.value;
  });
</script>
<?php }

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *