根据 WooCommerce 中的产品税 Class 调整运费 Class
Adjust Shipping Class based on Product Tax Class in WooCommerce
我目前正在尝试在 WooCommerce 中对产品和运输实施一些动态征税。到目前为止,我已经使用了这种方法:
WooCommerce Documentation on Tax Classes and User Roles
用于根据用户数据设置添加到购物车的产品的税收 Class。该数据是我创建的管理区域中的自定义复选框。如果选中该复选框,用户应该获得零税率征税。
这在很大程度上按预期工作,但最终产生了两个我无法解决的问题。
1) 结帐页面从未完全加载(订单摘要和付款选项面板上方有不断旋转的 'loading' 图标)
和
2)运费没有更新。具体来说,如果我从包含销售税和运费税的税 class 改为零税率,销售税会正确更新(到 none),但运费仍然有税。
我在 WooCommerce 设置中正确设置了税率(零税率没有运费税),但没有变化。
我正在使用这个过滤器来应用更改:
add_filter('woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 1, 2);
任何人都可以帮助我为购物车和结账正确设置运费吗?
There is a better way if you want a specific user role to be exempted of taxes. The WC_Customer
class has an interesting property which is "is_vat_exempt
".
可以将来自特定用户角色的所有客户设置为"Vat Exempt",方法如下:
add_action( 'template_redirect', 'is_user_vat_exempt' );
function is_user_vat_exempt(){
// Only for logged in users
if ( ! is_user_logged_in() )
return;
// Set specific user role "Vat exempt" if is not set yet
if ( current_user_can( 'some_user_role' ) && ! WC()->customer->is_vat_exempt() ) {
WC()->customer->set_is_vat_exempt( true );
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
这将解决您所有的问题,您需要删除不再需要的相关代码。
我目前正在尝试在 WooCommerce 中对产品和运输实施一些动态征税。到目前为止,我已经使用了这种方法: WooCommerce Documentation on Tax Classes and User Roles
用于根据用户数据设置添加到购物车的产品的税收 Class。该数据是我创建的管理区域中的自定义复选框。如果选中该复选框,用户应该获得零税率征税。
这在很大程度上按预期工作,但最终产生了两个我无法解决的问题。
1) 结帐页面从未完全加载(订单摘要和付款选项面板上方有不断旋转的 'loading' 图标) 和
2)运费没有更新。具体来说,如果我从包含销售税和运费税的税 class 改为零税率,销售税会正确更新(到 none),但运费仍然有税。
我在 WooCommerce 设置中正确设置了税率(零税率没有运费税),但没有变化。
我正在使用这个过滤器来应用更改:
add_filter('woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 1, 2);
任何人都可以帮助我为购物车和结账正确设置运费吗?
There is a better way if you want a specific user role to be exempted of taxes. The
WC_Customer
class has an interesting property which is "is_vat_exempt
".
可以将来自特定用户角色的所有客户设置为"Vat Exempt",方法如下:
add_action( 'template_redirect', 'is_user_vat_exempt' );
function is_user_vat_exempt(){
// Only for logged in users
if ( ! is_user_logged_in() )
return;
// Set specific user role "Vat exempt" if is not set yet
if ( current_user_can( 'some_user_role' ) && ! WC()->customer->is_vat_exempt() ) {
WC()->customer->set_is_vat_exempt( true );
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
这将解决您所有的问题,您需要删除不再需要的相关代码。