Advertisement
businessdad

WooCommerce - Calculate and display tax rate for a product

Jul 14th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Display the tax rate applicable to a product, on the single product page.
  3.  * Need help customising the code for your need? Hire us on Codeable: https://aelia.co/hire_us
  4.  */
  5. function exbtw_melding(){
  6.   global $product;
  7.  
  8.   $price_incl_tax = wc_get_price_including_tax($product);
  9.   $price_excl_tax = wc_get_price_excluding_tax($product);
  10.  
  11.   if(($price_incl_tax != 0) && ($price_excl_tax != 0)) {
  12.     // Determine the tax rate, with a maximum of two decimals
  13.     $tax_rate = round((($price_incl_tax / $price_excl_tax) - 1) * 100, 2);
  14.   }
  15.  
  16.   // Display a message with the tax rates
  17.   echo 'Alle vermelde prijzen zijn excl. <b>'. $tax_rate . ' BTW</b> / Tous les prix indiqués sont hors <b> '. $tax_rate . ' TVA</b>';
  18. }
  19.  
  20. add_action( 'woocommerce_before_add_to_cart_form', 'exbtw_melding', 20 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement