我得到了這個代碼,無論用戶指定什麼內容,都可以在用戶角色上免稅。特定產品ID上的每個用戶角色的稅率等級「零率」
但現在我需要另一個用戶角色,將免稅對特定產品ID,我不知道如何實現這一點。
使用的是現在對所有產品針對特定用戶角色免稅代碼IM是:
// Apply a different tax rate based on the user role.
function wc_diff_rate_for_user($tax_class, $product) {
// Getting the current user
$current_user = wp_get_current_user();
$current_user_data = get_userdata($current_user->ID);
if (in_array('administrator', $current_user_data->roles) || in_array('userrolename', $current_user_data->roles))
$tax_class = 'Zero Rate';
return $tax_class;
}
add_filter('woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2);
// Fin Apply a different tax rate based on the user role.
你需要角色??? –
是的,我只需要一個(或兩個)用戶角色就可以獲得特定產品ID的免費稅 –