Showing both Ex VAT and Inc VAT prices on a woocommerce product

Not only do we do repair computers here but also have a number of clients that we do website design and SEO for and one of our customers posed an interesting challenge for us recently.

We built a Woocommerce site for them and are promoting it through Google Ads while building the SEO.  They are mainly B2B so wanted to show all the prices Ex VAT which is easily achievable through the standard WooCommerce settings.

Recently however we have seen a number of live chat customers come on and ask about what the price is including VAT and we decided we should look at providing that too on the product page.

This proved to be surprisingly simple but yet was difficult to find the answer online as some product have variations, where as others do not so I thought I should share the below with you in case you also want to show both ext VAT and Inc VAT prices on a Woocommerce product page.

 

All you have to do is open the functions.php file in the Wordpress backend by going

 

 

Appearance --> Theme Editor 
show both ex VAT and inc VAT prices on woocommerce product

 

 

 
Then select the correct theme / Child Theme
how to show both ex VAT and inc VAT on a woocommerce product page

 

 

 Then select Theme Functions on the right. showing both ex VAT and inc VAT on woocommerce

 

 

All you have to do is copy in the below code into this file, save it and voila, your Woocommerce product page will now show both ex VAT and inc VAT prices :)

 

showing inc VAT and ex VAT on woocommerce product page

 

 

 

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

function edit_price_display() {

    global $product;

    $data = "<span class='amount'>" . woocommerce_price($product->get_price_excluding_tax()) . " <span style='font-size:0.5em;'>ex VAT</span></span>";

    $data .= "<span class='amount'><span style='text-align:right; color:#000000; font-size:0.5em;'>&nbsp&nbsp&nbsp&nbsp(" . woocommerce_price($product->get_price_including_tax()) . " inc VAT)</span></span>";

    return $data;

}



add_filter( 'woocommerce_available_variation', 'variation_price', 10, 3);

function variation_price( $data, $product, $variation ) {

    $data['price_html'] = "<span class='price'>" . woocommerce_price($variation->get_price_excluding_tax()) . " <span style='font-size:0.5em;'>ex VAT</span></span>";

    $data['price_html'] .= "<span class='price'><span style='text-align:right; color:#000000; font-size:0.5em;'>&nbsp&nbsp&nbsp&nbsp(" . woocommerce_price($variation->get_price_including_tax()) . " inc VAT)</span></span>";

    return $data;

}

 

Leave a comment

Please note, comments must be approved before they are published