Skip to content

Instantly share code, notes, and snippets.

@codeagencybe
Last active April 27, 2018 16:11
Show Gist options
  • Save codeagencybe/752d2e6551bd37cb6bf7762d738aabfd to your computer and use it in GitHub Desktop.
Save codeagencybe/752d2e6551bd37cb6bf7762d738aabfd to your computer and use it in GitHub Desktop.
WooCommerce show product VAT rating on product page
/**
* Display the tax rate applicable to a product, on the single product page.
*/
function show_product_vat_rating(){
global $product;
$price_incl_tax = wc_get_price_including_tax($product);
$price_excl_tax = wc_get_price_excluding_tax($product);
if(($price_incl_tax != 0) && ($price_excl_tax != 0)) {
// Determine the tax rate, with a maximum of two decimals
$tax_rate = round((($price_incl_tax / $price_excl_tax) - 1) * 100, 2);
}
// Display a message with the tax rates
echo 'All pricing is excluding <b>'. $tax_rate . ' VAT</b>';
}
add_action( 'woocommerce_before_add_to_cart_form', 'show_product_vat_rating', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment