我有两个不同的用户角色.厨师和顾客.对于厨师,我想要添加税,但对于客户,我不想添加税.问题是,对于Chef来说,像WooCommerce允许的那样增加税收没有问题.但我不想为用户角色Customer增加税收.
这就是我通过放入unctions.php来try 的方法,但它不起作用.
function exclude_tax_for_customer_role($cart) {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$user_roles = $user->roles;
// Check if the user has the "Customer" role
if (in_array('customer', $user_roles)) {
// Set tax amounts to zero
$cart->remove_taxes();
}
}
}
add_action('woocommerce_cart_loaded', 'exclude_tax_for_customer_role');