Display WooCommerce products with and without tax

I’ve recently run into the problem that is not possible for a WooCommerce shop to display both VAT and EX. VAT prices at the same time. Though this was possible in earlier version (if I remember correctly).

Sure, there are many plugins that are able to change the price suffix, but finding the right plugin can become a lengthy process and I like to code these fixes myself, but more importantly: it keeps your WordPress install clean from unnecessary code.

WooCommerce provides a lot of actions and filters which allows developers to change or add elements to their WooCommerce shop. The hook we need is the ‘woocommerce_get_price_html’, which allows us to change the way a price is displayed in the shop overview and on the product page.

Using WooCommerce settings

The quickest way of displaying the tax is through the WooCommerce settings. Log in to your admin dashboard and navigate to (depending on your language):

WooCommerce > Settings > Tax

And scroll down to: ‘Price Display Suffix’ or in Dutch: Prijsweergave-achtervoegsel.

If you are displaying the prices including VAT, you’ll have to add the following to the field:

{price_excluding_tax}

If you are displaying the prices excluding VAT, you’ll need to add:

{price_including_tax}

By hovering over the question mark, you’ll receive some detailed explanation on it’s usage.

Applying tax/vat to all WooCommerce products

Whilst using the WooCommerce settings is the most easiest way, you can also achieve it by filtering the WooCommerce price by adding our own function. This allows us to add our own classes with which we can style our price with!

Copy the code below into your functions.php to display both product prices, with and without taxes.

function edit_price_display() {
    global $product;
    $price = $product->price;
    $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);
    $price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
    $price = number_format($price, 2, ",", ".");
    $display_price = '<span class="price">';
    $display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small class="woocommerce-price-suffix"> incl BTW</small></span>';
    $display_price .= '<br>';
    $display_price .= '<span class="amount">€ ' . $price .'<small class="woocommerce-price-suffix"> excl BTW</small></span>';
    $display_price .= '</span>';
    echo $display_price;
}
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);

* Note that I live in the Netherlands, so we generally pay 21% taxes on most of our goods. To be sure, double check the tax percentage you pay in your country.

The ‘woocommerce_get_price_html’ hook is called everytime a product is displayed your screen.
– On line 2 and 3 we use the product ID to get it’s price.
– On the 4th line we calculate the amount of tax (21% of the normal price), round off the tax amount to 2 decimal behind the comma and add it to the original price.
– From line 6 to 12 we display the original price as well as the price including tax using the default WooCommerce price markup.
– Finally we echo the $display_price, in which we’ve save out HTML code.

Because we made use of the default WooCommerce classes, we let WooCommerce do all the hard work of styling the price output (we’re programmers, not designers :P).

Applying tax/vat only on the single WooCommerce product page

What if we only want to display the tax or vat on the single product page? Easy, just wrap the code into an if statement, checking if the page is a single product page. If so, calculate the price, if not return the normal price, passed as parameter in the function.

function edit_price_display($price, $instance) {
    global $product;

    if(is_singular('product')) {
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);
        $price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
        $price = number_format($price, 2, ",", ".");
        $display_price = '<span class="price">';
        $display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small class="woocommerce-price-suffix"> incl BTW</small></span>';
        $display_price .= '<br>';
        $display_price .= '<span class="amount">€ ' . $price .'<small class="woocommerce-price-suffix"> excl BTW</small></span>';
        $display_price .= '</span>';
        echo $display_price;
    } else {
        echo $price;	
    }
}
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);

Applying tax/vat to specific WooCommerce products

Below is an edit of the code above, allowing the code to function only for specific products by using their ID.
I’ve only added an if statement that compares the current product with the desired ID. I would only apply this for a maximum of 5 products, to keep everything neat and clean and. For even more products you should look at adding custom meta fields (like a checkbox) to a WooCommerce product in the WordPress dashboard, which is a more user friendly solution for those who aren’t experienced programmers.

function edit_price_display() {
    global $product;
    if($product->id == 'ID'){
         // Note that the 'ID' must be replaced by the specific product ID you want to change.
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 21 / 100 ), 2); 
        $price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
        $price = number_format($price, 2, ",", ".");
        $display_price = '<span class="price">';
        $display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small class="woocommerce-price-suffix"> incl BTW</small></span>';
        $display_price .= '<br>';
        $display_price .= '<span class="amount">€ ' . $price .'<small class="woocommerce-price-suffix"> excl BTW</small></span>';
        $display_price .= '</span>';
        echo $display_price;
    }
}
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);

Include and exclude VAT to a WooCommerce variation product price

The code above only works for the regular entered price in WooCommerce, but what if we have price variations? Simple, we just add one line below the already existing ‘add_filter’ .

add_filter('woocommerce_get_variable_price_html', 'edit_price_display', 10, 2);

With this additional ‘add_filter’ apply our function when WooCommerce calls the price for a product with several variations. This allows us to keep our code clean; creating functionality once and adding it to several WooCommerce filters!

function edit_price_display() {
    global $product;
    $price = $product->price;
    $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);  
    $price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
    $price = number_format($price, 2, ",", ".");
    $display_price = '<span class="price">';
    $display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small class="woocommerce-price-suffix"> incl BTW</small></span>';
    $display_price .= '<br>';
    $display_price .= '<span class="amount">€ ' . $price .'<small class="woocommerce-price-suffix"> excl BTW</small></span>';
    $display_price .= '</span>';
    echo $display_price;
}
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);
add_filter('woocommerce_get_variable_price_html', 'edit_price_display', 10, 2);

Cleaning up the variation product price

As the code above works, outputting all prices for every variation is an ugly solution. We can still use the same code for formatting the display, adding classes, custom messages, etc., we only need to change the hook we add our filter to from ‘woocommerce_get_variable_price_html’ to ‘woocommerce_available_variation’.

function edit_selected_variation_price( $data, $product, $variation ) {
    $price = $variation->price;
    $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);  
    $price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
    $price = number_format($price, 2, ",", ".");
    $display_price = '<span class="price">';
    $display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small class="woocommerce-price-suffix"> incl BTW</small></span>';
    $display_price .= '<br>';
    $display_price .= '<span class="amount">€ ' . $price .'<small class="woocommerce-price-suffix"> excl BTW</small></span>';
    $display_price .= '</span>';
    $data['price_html'] = $display_price;
    return $data;
}
add_filter( 'woocommerce_available_variation', 'edit_selected_variation_price', 10, 3);

Reactions are closed / Reacties zijn gesloten

Due to the high amounts of spam and other hateful messages, reactions to my blogs have been closed. I would like to refer you to my contact form if you have questions about my code, in need of my services and wanting to request a quote.

Door de grote hoeveelheid spam en andere vervelende berichten heb ik moeten besluiten om reacties op mijn blogs uit te zetten. Ik zou je daarom door willen verwijzen naar mijn contactformulier als je vragen hebt over mijn code, gebruik wilt maken van mijn diensten en een offerte aan wilt vragen.

64 reacties op “Display WooCommerce products with and without tax”

  1. Hi Tom,

    Shouldn’t that be
    add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’); instead of
    add_filter(‘woocommerce_price_html’, ‘edit_price_display’);?

  2. You need to put a date on your articles so we know if this is likely to work or not. WooCommmerce code changes constantly and I have no idea about nay of this.

  3. Hi there, I hope you could respond in time.

    I’ve taken the code above, which wonders! However, I need to customize this in almost no time at all. I’m sure I could figure it out but time is not on my side.

    Basically, the code is perfect but I need to have the following on a Single Product page ONLY, not outside this, like Widgets or site wide, ONLY on a Single Product page: What I need:

    Currently: Was $200, Now $100
    I need to add below:
    Price: $100
    Tax: 15$
    Total: $115

    And again, I only need this on a Single Product Page
    I’m still learning 🙂

    Hope you could help, but your solution is almost what I need and can’t find anything out there and I need this is a whim.

    All the best.
    Kind Regards.

    1. I’m sorry but is there a reason why no response? Just asking…it’s cool if you don’t want to help, just maybe say so.

      Thanks

      1. I’m truly sorry for my late response! I needed some time to form an applicable answer for you 🙂 Your solution lies in tweaking the code for showing the tax/vat for all products. Wrapping the code between an if statement, checking if the visitor is on a single product page should do the trick. I’ve added a section displaying how you could approach your issue! If you still need some help, feel free to contact me!

    1. You could add an if statement, checking $product->is_on_sale() to be true. Instead of storing $product->price in the $price variable, you could store the sale price in the variable using $product->get_sale_price();.

  4. Hello thanks for your info! so helpful.
    I am trying to remove (includes 21,90 VAT) below price at checkout.
    I mean id like it to be only VAT included not showing the amount related to VAT.
    Do you know how to accomplish it?
    Thank you so much

    1. You can change your basket and checkout display options in the WooCommerce settings – just set to display including tax.

    2. That’s correct Rob! You can change the VAT display settings on the Tax tab of the WooCommerce Settings in your WordPress admin enviroment.

  5. Hey, thanks for this – it’s great!

    Is there a way for it to display variable product prices correctly but only when you’re on the product page? Adding the add_filter(‘woocommerce_get_variable_price_html’, ‘edit_price_display’, 10, 2); doesn’t seem to be getting me anywhere, but I don’t want it to display the prices inc/ex tax until you’re on the actual product page!

    1. Hi Rob, thank you for your response and good to hear you found my blog useful. You should check the ‘woocommerce_get_price_html’ which probably interferes with you trying to display the correct result.

      If you’ve copied my code directly from the blog into your website, the price with and without VAT is displayed on all product price instances because of the ‘woocommerce_get_price_html’ hook. Try commenting out this hook to see if this will solve your issue!

      For a more advanced solution you could check out the ‘woocommerce_available_variation’ hook combined with some JavaScript/jQuery to display product prices only when a variation or option is selected.

  6. Hi,
    Is there a way to have the prices with tax in the email templates, while having the price without tax in cart and checkout?

    Thanks.

    1. Hi Ionut!

      There are multiple solutions for this, the easiest would be using plugins. I want to stress that I’m not familiar with these kind of solutions and prefer to shy away from them. Most of the time these sort of plugins are expensive and/or lack specific or desired functionality.

      A second solution is overriding the WooCommerce templates which can be found in your plugins folder in “woocommerce > templates > emails”. The template you are looking for should be the ‘email-order-details.php’. Can be a difficult fix if you’re not familiar with PHP or WooCommerce hooks.

      The third solution can be, just like this tutorial, using hooks and especially the ‘woocommerce_order_item_meta_start’ or the ‘woocommerce_order_item_meta_end’ hooks.

  7. Hello Thomas,

    thank you very much. I’m using woocommerce 4.0.1 and I’m putting to the woocommerce price include VAT, that’s mean I must little bit edit your code for showing also price excluding VAT and is it perfect.

    function edit_price_display() {
    global $product;
    $price = $product->price;
    $price_excl_tax = $price – ( $price – ( $price / ( ( 21 / 100 ) + 1 ) ) );
    $price_excl_tax = number_format($price_excl_tax, 2, “,”, “.”);
    $price = number_format($price, 2, “,”, “.”);
    $display_price = ”;
    $display_price .= $price .’ EUR ‘.’ incl. VAT’;
    $display_price .= ”;
    $display_price .= $price_excl_tax .’ EUR ‘.’ without VAT’;
    $display_price .= ”;
    echo $display_price;
    }
    add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’, 10, 2);

    But I’m not so good for edit also this code for ON SALE product. Please, can you help me, plese.

    1. Hi Rene,

      Good to hear that you’ve found my blog useful! At the moment, you’re only fetching the “normal” price of the product using $product->price. You could use an if statement in order to check if a product is on sale, if so, store the “sale price” in the price variable.

      Something like this could help you out:

      if( $product->is_on_sale() ) {
      return $product->get_sale_price();
      }

      If you need some more help, feel free to contact me!

      1. Hi Thomas,

        Thanks for the script..
        Where do I place the code for showing the Sale price?

        if( $product->is_on_sale() ) {
        return $product->get_sale_price();
        }

        My code:

        function edit_price_display() {
        global $product;
        $tax_class = $product->get_tax_class();
        if ($tax_class == ‘laag’) {
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 9 / 100 ), 2);
        $price_incl_tax = number_format($price_incl_tax, 2, “,”, “.”);
        $price = number_format($price, 2, “,”, “.”);
        $display_price = ”;
        $display_price .= ‘€ ‘ . $price .’ excl. BTW’;
        $display_price .= ”;
        $display_price .= ‘€ ‘ . $price_incl_tax .’ incl. BTW’;
        $display_price .= ”;
        echo $display_price;
        }
        elseif ($tax_class == ‘nul’) {
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 0 / 100 ), 2);
        $price_incl_tax = number_format($price_incl_tax, 2, “,”, “.”);
        $price = number_format($price, 2, “,”, “.”);
        $display_price = ”;
        $display_price .= ‘€ ‘ . $price .’ excl. BTW’;
        $display_price .= ”;
        $display_price .= ‘€ ‘ . $price_incl_tax .’ incl. BTW’;
        $display_price .= ”;
        echo $display_price;
        }
        else {
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);
        $price_incl_tax = number_format($price_incl_tax, 2, “,”, “.”);
        $price = number_format($price, 2, “,”, “.”);
        $display_price = ”;
        $display_price .= ‘€ ‘ . $price .’ excl. BTW’;
        $display_price .= ”;
        $display_price .= ‘€ ‘ . $price_incl_tax .’ incl. BTW’;
        $display_price .= ”;
        echo $display_price;
        }
        }
        add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’, 10, 2);

        1. Hi Erik,

          In your case you could add the ‘$product->get_sale_price();’ to the ‘$display_price’ string you echo per if statement, if a sale price is available.

          Small tip for cleaning up your code a little bit. You’re arranging the content of your ‘$display_price’ multiple times in more or less the same way. Try to retrieve any prices (sale or regular) once, including the tax calculations at the top in your ‘edit_price_display()’. When you have all your calculations and prices you could then format your HTML into one template.

  8. Hi Tom,

    Great tip! Works a treat on my site here in the UK with a few little tweaks. I’ve got a slight issue with the variation prices though. When I add the filter in it’s shows all the variation prices at the top of the webpage, and also under the short description?

    Is there any thing that could be causing this?

    Many thanks in advance,

    Nick

    1. Hi Nick!

      Glad to hear you found my blog useful! It’s a bit difficult not being able to see a live demo, but it sounds like the same issue Rob Thomas had a few months ago (februari). It could even be a result from a template having custom WooCommerce templates.

      Check if the ‘woocommerce_get_price_html’ filter interferes with displaying the price at the top of your page by commenting it out. If you only want to variation prices to be calculated, you don’t need to use the ‘woocommerce_get_price_html’ filter.

      If you need some more help, don’t hesitate to contact me!

      1. Hi Tom,

        Thanks for coming back to me. I’ve been having a look around, and I think i’m about 90% there now. Prices are displaying ok for simple products on category and product layout., and variable products are showing ok in category layout, it’s just the variable product simple layout that’s not working and still showing multiple price outputs.

        This is the code i’m using:

        function edit_price_display() {
        global $product;
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 20 / 100 ), 2);
        $price_incl_tax = number_format($price_incl_tax, 2, “.”, “.”);
        $price = number_format($price, 2, “.”, “.”);
        $display_price = ”;
        $display_price .= ‘From £’ . $price .’ + VAT’;
        $display_price .= ‘(£’ . $price_incl_tax .’ inc. VAT)’;
        $display_price .= ”;
        echo $display_price;
        }
        add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’, 10, 2);

        And if you look here: https://lathams-staging.zestdev.com/louvre-panels-and-vision-panels/louvre-panel/ you can see an example of all the outputted prices above the header in where the price should be.

        I was wondering if you had any thoughts what might be causing this?

        1. Awesome Nick, good to hear you’re almost there!

          Either the ‘$product->get_price_html();’ is called at the beginning of your body tag or there is another hook attached to your ‘edit_price_display’ filter.

          Check out the final section of this tutorial I’ve added recently. This allows you to only display a price of a selected variation, instead of all prices of all variations.

          1. Hi Tom,

            It’s getting there! Haha. I’ve tried merging the two strings together as you mention in the cleaning up the variation prices, using:

            function edit_price_display() {
            global $product;
            $price = $product->price;
            $price_incl_tax = $price + round($price * ( 20/100 ), 2);
            $price_incl_tax = number_format($price_incl_tax, 2, “.”, “.”);
            $price = number_format($price, 2, “.”, “.”);
            $display_price = ”;
            $display_price .= ‘£ ‘ . $price .’ +VAT’;
            //$display_price .= ”;
            $display_price .= ‘ (£ ‘ . $price_incl_tax .’ inc. VAT)’;
            $display_price .= ”;
            echo $display_price;
            }
            add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’, 10, 2);

            function edit_selected_variation_price( $data, $product, $variation ) {
            $price = $variation->price;
            $price_incl_tax = $price + round($price * ( 20/100 ), 2);
            $price_incl_tax = number_format($price_incl_tax, 2, “.”, “.”);
            $price = number_format($price, 2, “.”, “.”);
            $display_price = ”;
            $display_price .= ‘£ ‘ . $price .’ +VAT’;
            //$display_price .= ”;
            $display_price .= ‘ (£ ‘ . $price_incl_tax .’ inc. VAT)’;
            $display_price .= ”;
            $data[‘price_html’] = $display_price;
            return $data;
            }
            add_filter( ‘woocommerce_available_variation’, ‘edit_selected_variation_price’, 10, 3);

            But i’m still seeing the multiple prices on actual product page: https://lathams-staging.zestdev.com/security-front-doors/high-security-front-door/

            It does show ok on the category page: https://lathams-staging.zestdev.com/security-front-doors/

            I’ve noticed it’s not working for sale prices too, am i missing something?

          2. Hi Nick,

            It should be your ‘add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’, 10, 2);’. The ‘woocommerce_get_price_html’ is called every time any price is about to be displayed. Wrapping the contents of that function in an if statement checking for ‘is_product()’ will allow the code to display only when the visitor is on a single product page. Be aware that you are overwriting the code that displays the price on every page a price is displayed. Wrapping everything in a suggested if statement could cause all prices to disappear if the visitor isn’t on a single product page.

  9. hallo,
    ik werk als groothandel en vind dit wel handig om te gebruiken, alleen als ik dit toevoeg zijn de prijzen weg voor de dealers als ze inloggen ( krijgen andere prijzen )
    Hoe zit dat?

    1. Hoi Justin,

      Zeker een goeie vraag, lastig wanneer ik niet kan “meekijken”. Het kan eventueel aan 2 dingen liggen.

      1. Je maakt al gebruik van de standaard BTW instellingen op producten in WooCommerce. Ik zou daarom aanraden wanneer je mijn oplossing gebruikt om de product prijs altijd te tonen inclusief BTW. Wanneer je mijn oplossing toepast op prijzen waar al BTW van af is getrokken krijg je inderdaad het verkeerde resultaat te zien.

      2. Maak je toevallig gebruik van een plugin waar producten alleen zichtbaar zijn voor ingelogde gebruikers? Deze tutorial is namelijk geschreven voor een “schone” WooCommerce installatie, zonder enige third-party plugins. Soms kan het zijn dat plugins standaard functionaliteit “overrulen”.

      Mocht je er niet uit komen hoor ik dat alsnog graag!

  10. very useful codes.
    If i only want to display the extra excluding tax price on the products detail page.where i should paste the codes.
    someone told me modify price.php but i didnt find this file at all.

    1. Hi Wang,

      I try not to edit any WooCommerce template files when other solutions are available. All my solutions are based on placing code in either the functions.php file of your currently active theme or in a custom plugin.

  11. Hello,
    thank you very much for good tutorial. This works very good on standard products. I am a designer, so I styled it my way:
    https://s12.directupload.net/images/200604/cqvheb8g.png

    But on variable products adding filter
    add_filter(‘woocommerce_get_variable_price_html’, ‘edit_price_display’, 10, 2);
    does not work properly
    https://s12.directupload.net/images/200604/z9s2msgz.png

    See it here:
    https://naj.dev.x3o.cc/obchod/drevene-detske-ihriska/smykacky-smyklavky-tobogany-agatove-detske-ihriska/nerezova-smykacka-na-svah/

    Thank you very much for your help

    1. The price of that variable product is also variable, so there should not be all the time the same price, but also should adjust according to selected variation

    2. Hi Miroslav,

      Please check the “Cleaning up the variation product price” section I’ve created at the bottom of the tutorial. Using the ‘woocommerce_available_variation’ hook allows you to hook into the “variation selection process” of WooCommerce, retrieving the product price based on the current selected attributes.

        1. Hi Miroslav,

          Good to hear it’s starting to work! I think you still have the ‘woocommerce_get_variable_price_html’ hook on your ‘edit_price_display’ function? Removing this should solve your issue!

          1. No, I deleted it.
            Still the same: Simple product All Good, Variable product, still all prices displayed.
            ****************
            HERE IS MY FULL CODE:

            function edit_price_display() {
            global $product;
            $price = $product->price;
            $price_incl_tax = $price + round($price * ( 20 / 100 ), 2);
            $price_incl_tax = number_format($price_incl_tax, 2, “,”, “.”);
            $price = number_format($price, 2, “,”, “.”);
            $display_price = ”;
            $display_price .= ‘€ ‘ . $price .”;
            $display_price .= ”;
            $display_price .= ‘€ ‘ . $price_incl_tax .’ s DPH’;
            $display_price .= ”;
            echo $display_price;
            }
            add_filter(‘woocommerce_get_price_html’, ‘edit_price_display’, 10, 2);

            function edit_selected_variation_price( $data, $product, $variation ) {
            $price = $variation->price;
            $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);
            $price_incl_tax = number_format($price_incl_tax, 2, “,”, “.”);
            $price = number_format($price, 2, “,”, “.”);
            $display_price = ”;
            $display_price .= ‘€ ‘ . $price .”;
            $display_price .= ”;
            $display_price .= ‘€ ‘ . $price_incl_tax .’ s DPH’;
            $display_price .= ”;
            $data[‘price_html’] = $display_price;
            return $data;
            }
            add_filter( ‘woocommerce_available_variation’, ‘edit_selected_variation_price’, 10, 3);

          2. Hi Miroslav,

            Could you check what happens if you remove or comment out the entire ‘woocommerce_get_price_html’?

  12. Hi Thomas,

    Thank you for the great tutorial! I’m trying to combine both prices too, like Miroslav and Davide. I’m using simple products, variable products and variable products with different prices. Combining the 2 functions do work good, but a problem occures (only) with variations that have different prices. Then it displays all prices below ech other (incl. and excl. VAT).
    It would be great to have a fix for this!

  13. Hi Thomas
    Thanks for some nice tips! I would like to have a productcategory for privates and another for companys. So my private category is incl. taxes, and my company category is excl. tax. How do I achieve this ?
    Hope to hear from you soon. 🙂
    Henrik

    1. Hi Henrik,

      Could you elaborate a bit more on your desired functionality? Do you mean display VAT based on logged in users or product prices including VAT based on the product’s category?

  14. Hi, if I want to show the price on the product page including tax and I want next to it to have quoted only the amound of applied tax in dollars (for example I have 10% vat applied in a 20dollars product, so in the display to be the (price included tax) + (the amount of included tax)
    22$ (2$ TAX)
    Is any of your code lines above helping me do that on single or either variable products? have you any idea how to do that?
    For example the woocommerce by itself gives u the opportunity to add next to the price the price including tax by adding Price Display Suffix: {price_including_tax}.
    Is there a way to add only the amount of tax (in money value) next to the prices??
    Thanx in advance mate

    1. Hi Panos,

      This can be achieved using the code in the final section of my tutorial, ‘Cleaning up the variation product price’. You could replace all lines starting with ‘$display_price = …’ for ‘$display_price .= ‘‘ . $price . ‘$ (‘ . round($price * ( 21 / 100 ), 2) .’$ TAX)‘;’. In your case you won’t be needing the two lines starting with ‘$price_incl_tax = …’, might as well remove them!

  15. Hi,

    ik gebruik onderstaande code:

    function edit_selected_variation_price( $data, $product, $variation ) {
    $price = $variation->price;
    $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);
    $price_incl_tax = number_format($price_incl_tax, 2, “,”, “.”);
    $price = number_format($price, 2, “,”, “.”);
    $display_price = ”;
    $display_price .= ‘€ ‘ . $price_incl_tax .’ incl BTW’;
    $display_price .= ”;
    $display_price .= ‘€ ‘ . $price .’ excl BTW’;
    $display_price .= ”;
    $data[‘price_html’] = $display_price;
    return $data;
    }
    add_filter( ‘woocommerce_available_variation’, ‘edit_selected_variation_price’, 10, 3);

    de product pagina werkt prima zowel simple als voor variable producten.
    alleen op de categorie overzicht pagina worden de prijzen alleen ex btw getoond en niet meer ex btw en in btw.

    is dat op te lossen?

    1. Hi Danny,

      Dit komt waarschijnlijk doordat er geen keuze gemaakt kan worden op de categorie of overzicht pagina’s. Je zou de ‘woocommerce_get_price_html’ hook aan kunnen passen door te checken of de bezoeker op bijv. een categorie pagina zit (‘if(is_product_category()’), vervolgens te kijken of het product variaties heeft om als laatste alleen een vanaf prijs te tonen (inclusief en exclusief btw) of de enkele prijs van een product (zonder variaties) inclusief en exclusief btw. Kun je hier wat mee?

  16. Top tip! Heb je een tip over werken met multicurrency en WPML? Wij gebruiken multicurrency dollar en euro. Alleen in de code staat hard een euro. Kan dit vervangen voor het actieve teken?

    Groet,
    Kees

    1. Hi kees,

      Dat is zeker mogelijk, de netste/snelste optie is door de product prijs door de ‘wc_price($product_price);’ te halen. Die haalt, op basis van WooCommerce instellingen, het juiste valuta symbool op!

  17. Hi Thomas,

    Thanks for the tutorial. I was wondering if you have any suggestions for our case: we are mostly selling products inside the EU. This is why we decided to display our products including VAT. However, for our US customers, we would like to exclude the VAT, and calculate the VAT on top of the price at the checkout. So in our case a country based VAT rule would be the best option. Your snippets gave me some ideas, but I can’t really figure out where to start. Any suggestions? Thanks in advance!

    Joel

    1. Hi Joel,

      Great question! First I would check the current visitor’s location. In the past I’ve used the ‘WC_Geolocation::geolocate_ip();’ function in order to retrieve the country code (e.g. ‘NL’ or ‘US’). Though I’m not sure if it’s still being supported by WooCommerce because of the GDPR policy. If so, I would use the visitor’s location (if it’s available) to check against a list of European countries in order to calculate prices according to the country’s VAT percentage or rules. Finally you will be able to display the price according to examples from my tutorial!

      In addition for visitor’s from the US I would only display the necessary VAT calculations using the ”woocommerce_review_order_before_order_total’ hook at the order review/checkout and possibly in the cart using ”woocommerce_before_cart_totals’, if that’s customary in the US.

  18. Is there a way of not having the VAT price show up on zero rated products? At the moment it’s adding VAT even thought the product is set no tax and zero rated.

    1. Hi Paula,

      You can check if a product is taxable (if you’ve set it in the general settings of a product) by using the `is_taxable()` method in an if statement, wrapping the code that calculates the tax!

  19. The code works great when it is a simple product, but when it is already variable and on top of it changes in prices, the code crashes there

    I do not know if you would be so kind as to make a code that solves all these problems of variability and price changes in variable products?

    1. Hi Roleman,

      I’m not sure if I understand your issue completely, so feel free to correct me where I make the wrong assumptions!

      Have you checked the ‘Cleaning up the variation product price’ section of the tutorial? This should show and calculate the price for product variations!

  20. Hi Thomas,

    Wij zitten met een klant met een speciale vraag. Hij wil graag sommige producten tonen inclusief BTW (voor normale consumenten) en een aantal specifieke producten excl BTW (voor zakelijke gebruikers). In de cart kan alles berekend worden zoals je zou verwachten, gaat dus vooral om de single product. Het betreft alleen niet ingelogde gebruikers dus we kunnen niet werken met user roles.
    Heb jij hier een slimme oplossing voor?

    Thanks!

    1. Hi Ruben,

      Ik hoop dat ik je goed begrijp, maar ben je toevallig op zoek naar het uitbreiden van je product met custom meta velden? Denk daarbij aan een ‘BTW checkbox’ onder de algemene product instellingen tab, welke je aan of uit kan vinken. Aangevinkt is de prijs voor zakelijke gebruikers, uitgevinkt is voor consumenten. De waarde van deze custom meta zou je in een soortgelijke code als hierboven uit kunnen lezen om vervolgens een eventuele prijsberekening te tonen!

      Het is altijd lastig om zoiets ‘blind’ te doen, dus ik hoop dat je hier wat aan hebt! Anders zou je mij altijd nog een mailtje kunnen sturen!

      Succes!

Reacties zijn uitgeschakeld.