注文した内容に関係なく、ユーザーロールに対して税金を適用するこのコードを入手しました。これは問題ありません。特定の製品IDのユーザーロールごとの税率クラス「ゼロレート」
しかし、特定の製品IDに税金無料のを適用する別のユーザーの役割が必要です。これをどのように実現するかわかりません。特定のユーザロールのすべての製品の非課税のために今使用して
コードイムは、次のとおりです。
// 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の –