"includes $x VAT estimated for {country} "在WooCommerce购物车和结帐



我已经将增值税设置为包括数字商品的税款。在我的购物车和结帐中,总金额后出现税款为:

"(包括$ xy增值税)"

我更喜欢在其他商店网站上看到的东西:

"(包括为德国估计的$ XY增值税)

我的问题:

1)这是我使用的主题的自定义化,是插件还是可以在WooCommerce中设置此插件?地理位置设置的购物车上的估计国家吗?

2)我可以用钩子或过滤器将估计的税收文本定位在价格之前吗?

对于问题2,请尝试一下

add_filter( 'woocommerce_cart_total', 'wc_prefix_text_on_price' ); 
function wc_prefix_text_on_price( $price ) {
    $prefix = 'estimated tax';
    return  $prefix . $price;
}

更改"包括[country]]的增值税"。在WooCommerce Checkout页面上的消息,您可以使用woocommerce_cart_totals_shipping_html过滤器。

这是如何更改消息的示例:

add_filter( 'woocommerce_cart_totals_shipping_html', 'custom_checkout_vat_message' );
function custom_checkout_vat_message( $shipping_html ) {
// Get the customer's country
$customer_country = WC()->customer->get_shipping_country();
// Get the tax rate for the customer's country
$tax_rate = WC_Tax::get_rates( $customer_country )[1]['rate'];
// Calculate the VAT amount
$vat_amount = WC()->cart->shipping_total * $tax_rate / 100;
// Format the VAT amount as a price
$formatted_vat = wc_price( $vat_amount );
// Replace the message with your custom message
$new_message = 'Price includes VAT of ' . $formatted_vat . ' for ' . $customer_country;
$shipping_html = str_replace( 'includes ' . wc_price( WC()->cart->get_shipping_tax() ) . ' VAT estimated for ' . $customer_country, $new_message, $shipping_html );
return $shipping_html;

}

在此示例中,我们使用WC_TAX :: get_rates()方法来获取客户国家/地区的税率,然后根据购物车的运输总计计算增值税金额。然后,我们使用wc_price()将增值税数量格式化为价格,并使用str_replace()的自定义消息替换原始消息。