After a client asked to show the prices of products from a woocommerce website that would show Included and Excluded VAT prices, I thought this would be simple!
I searched “woocommerce display tax rate”, and tried many ways and nothing seemed to work!
I thought Woocommerce would have this function within it. I was wrong. How easy it would be to add an option that would include this!
The option would say “Do you want to include both prices?” and then another box that says the rate at which you want it to apply. But alas no such thing!
I started to search for a simple plugin (woocommerce tax plugin) that would include this but they were either very complex and did not answer my problem or they were very costly and complex!
Eventually I came across a very simple bit of code that will show the variable product price with VAT and without VAT and when the user selects another option of that product like colour or size it will trigger the code again to show the new updated price with VAT and without again. Yay!
Why is this not an option???
Just add this code to the bottom of your functions.php file and your done.
Please then click the “Was this helpful button”, and let me know…..
Latas….
1 2 3 4 5 6 7 8 |
add_filter( 'woocommerce_available_variation', 'my_variation', 10, 3); function my_variation( $data, $product, $variation ) { $data['price_html'] = "<span class='ex-vat-price'>ex. " . woocommerce_price($variation->get_price_excluding_tax()) . "</span><br>"; $data['price_html'] .= "<span class='inc-vat-price'>inc. " . woocommerce_price($variation->get_price_including_tax()) . "</span>"; return $data; } |