Někdy je potřeba na webu zobrazovat cenu s DPH i bez DPH. K tomu slouží hooky ‘woocommerce_get_price_html’, který upraví zobrazení cen všude na webu, a ‘woocommerce_cart_item_price’, který změní zobrazení u položek v košíku.
add_filter('woocommerce_get_price_html', 'show_price_with_and_without_tax', 20, 2);
add_filter( 'woocommerce_cart_item_price', 'show_price_with_and_without_tax', 20, 3 );
function show_price_with_and_without_tax($price, $product) {
if (!$product->is_taxable()) {
return $price;
}
$price_excluding_tax = wc_get_price_excluding_tax($product);
$price_including_tax = wc_get_price_including_tax($product);
return wc_price($price_excluding_tax) . '<span class="price-exl-tax-suffix"> ' . __( 'bez DPH', 'woocommerce' ) . '</span><br>' . wc_price($price_including_tax) . '<span class="price-incl-tax-suffix"> ' . __( 'vč. DPH', 'woocommerce' ) . '</span>';
}