SHOW:
|
|
- or go back to the newest paste.
| 1 | - | add_action( 'woocommerce_before_add_to_cart_form', 'exbtw_melding', 20 ); |
| 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 | - | global $product; |
| 4 | + | */ |
| 5 | - | // $tax_rates = $product->get_tax_class(); |
| 5 | + | |
| 6 | - | $tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); |
| 6 | + | global $product; |
| 7 | - | // $tax_rates = $product->get_rates(get_tax_rates()); |
| 7 | + | |
| 8 | - | echo 'Alle vermelde prijzen zijn excl. <b>'. $tax_rates . ' BTW</b> / Tous les prix indiqués sont hors <b> '. $tax_rates . ' TVA</b>'; |
| 8 | + | $price_incl_tax = wc_get_price_including_tax($product); |
| 9 | - | } |
| 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 ); |