wooccommerce/Cart页面中的基于角色的税收



我已经建立了一个有多个用户的wooccommerce商店(B2C和B2B)。他们中的一些人将自动免税,只需从购物车/结账中删除税款。我使用了一个动态定价插件为不同的角色提供不同的价格,但没有税收变化的选项。

我找到了这个答案,并试图在wooccommerce中实施基于角色的税收,但正如@Jplus2所说,@dryan144解决方案并不好,因为它只在结账时应用,而不在购物车上。我试着想办法做到这一点,但我仍然必须刷新我的"购物车"页面,将税款显示为0(因为它们包含在"客人"或"客户"的价格中,当我的购物车页面被调用时,有什么帮助可以启动操作吗?

我做了以下事情:

add_filter( 'woocommerce_before_cart_contents', 'prevent_wholesaler_taxes' );
add_filter( 'woocommerce_before_shipping_calculator', 'prevent_wholesaler_taxes' );
add_filter( 'woocommerce_before_checkout_billing_form', 'prevent_wholesaler_taxes' );
function prevent_wholesaler_taxes() {
global $woocommerce;
if ( is_user_logged_in() && !(current_user_can('customer'))){
$woocommerce->customer->set_is_vat_exempt(false);
} else {
$woocommerce->customer->set_is_vat_exempt(true);
}
} //end prevent_wholesaler_taxes

它有时会直接工作,但大多数时候都是在我的购物车刷新后才工作,这并不好。尝试添加https://eshoes.com.au/product/test-shoes08/到购物车,然后->查看您的购物篮

任何帮助都将不胜感激;)

干杯

此解决方案非常有效,而不是使用set_is_vat_exempt()我只是使用$tax)class="零税率":

add_filter( 'woocommerce_before_cart_contents', 'wc_diff_rate_for_user', 1, 2 );
add_filter( 'woocommerce_before_shipping_calculator', 'wc_diff_rate_for_user', 1, 2);
add_filter( 'woocommerce_before_checkout_billing_form', 'wc_diff_rate_for_user', 1, 2 );
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );
function wc_diff_rate_for_user( $tax_class ) {
if ( !is_user_logged_in() || current_user_can( 'customer' ) ) {
$tax_class = 'Zero Rate';
}
return $tax_class;
}

最新更新