WooCommerce show single product with and without VAT

  php, woocommerce, wordpress

I’m trying to show price with and without VAT on every Single Product page in a WooCommerce store.

I already done it for variable products with the script below, thanks to the WooCommerce_available_variation hook:

add_filter( 'woocommerce_available_variation', 'my_variation', 10, 3);
function my_variation( $data, $product, $variation ) {
    $data['price_html'] = "<bdi><span class='inc-vat-price'></span>" . woocommerce_price($variation->get_price_including_tax()) . "</bdi><br>";
    $data['price_html'] .= "<bdi><span class='ex-vat-price'>Tax Free - </span>". woocommerce_price($variation->get_price_excluding_tax()) . "</bdi>" ;
    return $data;
}

Instead, for a Single Product, I haven’t found any solution.

By modifying the Price.php file of the Single Product in WooCommerce, the price without Vat is repeated also in the variable products. In this case I have used the code:

$product->get_price_excluding_tax()

What is a possibile solution to this problem?

Thank you so much for your support!

Source: Ask PHP

LEAVE A COMMENT