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.


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 }








