在这里,当前的模板显示了不包括增值税的价格和我想添加的说明,包括它们之间的税款,它不起作用
<script type="text/template" id="tmpl-variation-template">
<div class="woocommerce-variation-price">
{{{ data.variation.price_html }}}
</div>
<div class="price-vat">
<!-- Here display price including tax -->
</div>
<div class="woocommerce-variation-description">
{{{ data.variation.variation_description }}}
</div>
<div class="woocommerce-variation-availability">
{{{ data.variation.availability_html }}}
</div>
</script>
在您的functions.php:)
中尝试一下它返回变异价格,不包括税前和包括税后的税款。您可以编辑此功能以添加措辞/样式等。
您可能需要使用WC_PRICE而不是WooCommerce_price,如WooCommerce版本2.6 。
add_filter( 'woocommerce_available_variation', 'my_variation', 10, 3);
function my_variation( $data, $product, $variation ) {
$data['price_html'] = "<span class='ex-vat-price'>ex. " . woocommerce_price($variation->get_price_excluding_tax()) . "</span><br>";
$data['price_html'] .= "<span class='inc-vat-price'>inc. " . woocommerce_price($variation->get_price_including_tax()) . "</span>";
return $data;
}
来源:我修改了此处找到的代码。