Sim*_*nto 2 php wordpress user-roles woocommerce tax
在我的woocommerce网站上,我已在常规WooCommerce设置中启用了Tax。
我想从我的商店,结帐页面和订单电子邮件中以编程方式(使用任何钩子)为特定用户角色禁用税收。
我怎样才能做到这一点?
谢谢
您不能以编程方式禁用特定用户角色的WooCommerce税,但是可以以零税率申请特定用户角色。
首先,您需要在worpress中设置此特定用户角色。如果是这种情况,那么可以说此自定义用户角色是'resellers'
我的代码示例。
其次,您必须在WooCommerce设置中启用零税率:
然后,对于每个国家/地区,您都必须将税率设置为零:
第三-然后,此函数挂接即可woocommerce_product_tax_class
:
function zero_rate_for_custom_user_role( $tax_class, $product ) {
// Getting the current user
$current_user = wp_get_current_user();
$current_user_data = get_userdata($current_user->ID);
// <== <== <== <== <== <== <== Here you put your user role slug
if ( in_array( 'resellers', $current_user_data->roles ) )
$tax_class = 'Zero Rate';
return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'zero_rate_for_custom_user_role', 1, 2 );
Run Code Online (Sandbox Code Playgroud)
您只需要放置所需的用户角色插件即可,而不是“经销商”。
这段代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中。
此代码已经过测试,功能齐全。
参考:WooCommerce-为某些特定用户角色启用“零费率”税类
归档时间: |
|
查看次数: |
1390 次 |
最近记录: |